Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,810 --> 00:00:05,640
In the last section, we created a new fetch image method right here, so the purpose of this method
2
00:00:05,640 --> 00:00:12,960
is going to be to make an HTTP request to that outside API, fetch the JSON for one image and then create
3
00:00:12,960 --> 00:00:15,840
a new instance of the image model class out of it.
4
00:00:16,820 --> 00:00:22,100
But clearly, the first thing that we need to do inside of here is make an HTTP request in order to
5
00:00:22,100 --> 00:00:22,880
make a request.
6
00:00:22,910 --> 00:00:26,380
We're going to import a new package into our dart file.
7
00:00:26,900 --> 00:00:31,480
So at the very top up here, I'm going to import a package.
8
00:00:31,490 --> 00:00:38,810
So package Colon called HTP and I want the dart file out of their.
9
00:00:39,920 --> 00:00:46,040
The package is installed into all new flutter projects by default, so we don't have to do any additional
10
00:00:46,040 --> 00:00:49,010
installation, we can just import it directly into our project.
11
00:00:51,020 --> 00:00:57,950
Now, inside of this package, which is maintained by the DART team, we get a ton of different functions
12
00:00:57,950 --> 00:01:00,150
for making HTP requests.
13
00:01:00,770 --> 00:01:07,100
The only function that you and I actually care about is a specific function called get the get function
14
00:01:07,100 --> 00:01:11,100
allows us to, as you might guess, can get HTTP requests.
15
00:01:11,660 --> 00:01:16,040
Let's very quickly look at some documentation around this package just to get a better idea of what's
16
00:01:16,040 --> 00:01:16,490
going on.
17
00:01:17,870 --> 00:01:23,600
OK, so not the documentation which is at GitHub, dotcom start dangling.
18
00:01:25,550 --> 00:01:27,650
So this is the GitHub repository for it.
19
00:01:28,010 --> 00:01:32,660
If you want to, you can visit it on darte leg or pub right here as well.
20
00:01:33,260 --> 00:01:36,220
And we can pull up some of the documentation over here if we want to.
21
00:01:36,770 --> 00:01:39,260
So on the right hand side, you'll find API docs.
22
00:01:40,810 --> 00:01:46,330
We can go there and it will pull up the documentation, so again, ton of functionality tied to this
23
00:01:46,330 --> 00:01:53,530
thing inside of specifically this HTP library right here that is inside of the package.
24
00:01:54,100 --> 00:01:56,620
On the right hand side, you'll see that we get our list of functions.
25
00:01:57,070 --> 00:02:00,330
And so the only function we care about is the function right here.
26
00:02:00,910 --> 00:02:07,630
We use this to make a request to some outside URL so we can call ticket function with some URL and it's
27
00:02:07,630 --> 00:02:09,039
going to make the request.
28
00:02:09,639 --> 00:02:14,260
Now, you'll notice that the return type, which is annotated to the left of the get word right here,
29
00:02:14,500 --> 00:02:15,910
is something called a future.
30
00:02:16,150 --> 00:02:17,620
We'll talk about what that isn't just a moment.
31
00:02:17,980 --> 00:02:23,230
But first, I want to discuss one other little interesting thing about the import statement that we
32
00:02:23,230 --> 00:02:23,800
just wrote.
33
00:02:25,560 --> 00:02:32,400
So we just wrote out an import to grab every single class, every single function, every single property
34
00:02:32,550 --> 00:02:37,490
inside of the package and import it into our current working file.
35
00:02:38,040 --> 00:02:44,160
And as you can see over here, there is a tremendous amount of code not only inside of HTP right here,
36
00:02:44,430 --> 00:02:51,540
but potentially inside of those other libraries of Browsr clients and testing that are part of the package
37
00:02:51,540 --> 00:02:52,020
as well.
38
00:02:52,860 --> 00:02:59,760
So when we write that one import statement, we are adding a ton of code into our project when actually
39
00:02:59,760 --> 00:03:04,160
you and I only care about this one function right here, just the git function.
40
00:03:04,590 --> 00:03:07,090
We don't care about anything else inside this package.
41
00:03:07,710 --> 00:03:14,430
So in order to avoid importing all those additional classes and all those additional functions, we
42
00:03:14,430 --> 00:03:16,770
can make a little change to our import statement.
43
00:03:17,380 --> 00:03:26,970
So up here after the package name, I'm going to write out as or some not as but show get like.
44
00:03:26,970 --> 00:03:27,240
So.
45
00:03:27,930 --> 00:03:29,550
So by putting on a show, get right here.
46
00:03:29,580 --> 00:03:31,410
This means that this tells darte.
47
00:03:31,410 --> 00:03:31,710
Yeah.
48
00:03:31,710 --> 00:03:38,010
We understand HTTP has just like a billion different classes and functions tied to it, but out of all
49
00:03:38,010 --> 00:03:41,430
those we only care about this one git function.
50
00:03:41,760 --> 00:03:43,720
So dump everything else inside there.
51
00:03:43,740 --> 00:03:44,610
We don't care about it.
52
00:03:44,790 --> 00:03:46,740
Just give us this one function.
53
00:03:48,160 --> 00:03:52,390
OK, so that's just going to avoid us importing unnecessary code into our project.
54
00:03:53,050 --> 00:03:54,130
So now that we've got
55
00:03:57,000 --> 00:04:02,110
more time HTP imported into our project and we've got only the get function.
56
00:04:02,470 --> 00:04:03,460
Let's take a quick break.
57
00:04:03,460 --> 00:04:06,940
We'll come back to the next section and make it use that to make an actual request.
58
00:04:07,160 --> 00:04:08,410
So I'll see you in just a minute.
5657
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.