Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,650 --> 00:00:06,960
In the last section, we spoke about how our jet function right here returns a future, we get back
2
00:00:06,960 --> 00:00:12,660
a future because we have to wait for that request to be completed before we can actually access the
3
00:00:12,660 --> 00:00:14,730
JSON data, the data that we get back.
4
00:00:15,760 --> 00:00:21,690
So in order to work with the future that comes back, I'm going to use the async 08 syntax to do so.
5
00:00:21,700 --> 00:00:28,030
I'll first mark the inclosing function as being async by putting the async keyword right after my argument
6
00:00:28,030 --> 00:00:28,420
list.
7
00:00:29,110 --> 00:00:34,660
Then in front of the git function, I will write out the await keyword, which tells Darte We need to
8
00:00:34,660 --> 00:00:39,580
wait for the future that gets returned from the get function to be resolved before we can work with
9
00:00:39,580 --> 00:00:40,420
the actual data.
10
00:00:41,660 --> 00:00:48,170
So then after we await that, we're going to take whatever information we got back from the AP and assign
11
00:00:48,170 --> 00:00:50,930
it to a new variable that we will call response.
12
00:00:52,530 --> 00:00:54,780
And claps aside so we can see a little bit.
13
00:00:55,030 --> 00:00:55,370
OK.
14
00:00:56,910 --> 00:01:02,100
Now, one thing I want to point out here is, is that this response variable is not the actual JSON
15
00:01:02,100 --> 00:01:02,480
data.
16
00:01:02,910 --> 00:01:07,890
The response variable is an object that tells us a little bit about the entire response that came back
17
00:01:07,890 --> 00:01:08,720
from that API.
18
00:01:09,000 --> 00:01:15,300
So it contains status codes, headers, a lot of information about the actual request that or the response
19
00:01:15,300 --> 00:01:21,540
that came back from the request that JSON data that we actually care about is nested inside of that
20
00:01:21,540 --> 00:01:22,500
response object.
21
00:01:23,580 --> 00:01:27,690
So now that we've at least got something that contains the Jason day that we care about, we can now
22
00:01:27,690 --> 00:01:33,480
take that, Jason, we can decode it and then we can create a new image model instance from it.
23
00:01:34,330 --> 00:01:38,640
So to get started with that, I'm going to first make sure that I import that image model class that
24
00:01:38,640 --> 00:01:40,290
we created a couple of seconds ago.
25
00:01:41,450 --> 00:01:47,270
Up at the top of the file, I'm going to import and remember, this is an important statement for a
26
00:01:47,270 --> 00:01:52,070
file that you and I wrote, so we don't have to write out the package keyword or the package word here.
27
00:01:52,280 --> 00:01:54,950
We just write out the path to the file that we want to get.
28
00:01:55,390 --> 00:01:57,700
So we're currently inside of Apte Dart.
29
00:01:58,070 --> 00:02:02,930
We're going to go into the models directory and then get the image underscore model, dot, dot, file.
30
00:02:03,530 --> 00:02:06,530
So let's say models slash image.
31
00:02:07,530 --> 00:02:10,470
Oops, image model that darts.
32
00:02:12,560 --> 00:02:15,650
OK, so that works now down here.
33
00:02:16,800 --> 00:02:25,020
Right after we take that response back, we're going to create a new image model instance, so say var
34
00:02:25,050 --> 00:02:28,970
image model equals image model.
35
00:02:29,760 --> 00:02:34,930
We want to take the JSON out of this response object and construct a new image model with it.
36
00:02:35,250 --> 00:02:38,130
So I'm going to call the named constructor from Jason.
37
00:02:39,360 --> 00:02:45,630
And I'm going to pass in that, Jason, from the response object, which is available on response dogsbody.
38
00:02:46,640 --> 00:02:49,380
Now, before we leave it right here, we did miss one step.
39
00:02:50,060 --> 00:02:50,840
Do you know what we missed?
40
00:02:51,500 --> 00:02:53,410
Well, this right here is Jason Data.
41
00:02:53,420 --> 00:02:55,040
It's still that raw, Jason.
42
00:02:55,230 --> 00:03:02,030
So we first have to decode that, Jason, and we decode it by writing out Jason Dot Decode.
43
00:03:03,030 --> 00:03:05,640
And we pass in the response body like so.
44
00:03:08,190 --> 00:03:13,230
OK, now you'll notice that Jason is red right here, says Undefined, named Jason, that is because
45
00:03:13,230 --> 00:03:19,370
we have not imported the package from the dark standard library that contains the JSON object.
46
00:03:19,980 --> 00:03:27,660
So at the very top, I'm going to make sure that I also add on an import statement for darte colon convert.
47
00:03:28,710 --> 00:03:33,660
The convert module that's part of the DART Senior Library is where we get that JSON object from.
48
00:03:35,390 --> 00:03:36,980
So we now get back our response.
49
00:03:37,990 --> 00:03:44,860
The actual raw JSON is available on response to body, we decode that, that gives us some pass JSON
50
00:03:45,220 --> 00:03:51,550
and then we use the front JSON named constructor that we created to create a new image model instance.
51
00:03:52,240 --> 00:03:52,870
And that's it.
52
00:03:53,110 --> 00:03:53,950
That's pretty much it.
53
00:03:55,030 --> 00:03:56,940
So we've now got our image model.
54
00:03:57,520 --> 00:03:58,900
We've definitely made some progress.
55
00:03:58,900 --> 00:04:03,490
But you'll notice that we're not really doing anything with image model just yet.
56
00:04:04,010 --> 00:04:08,500
So let's take a quick pause right here and we'll talk about what we're going to now do that we have
57
00:04:08,500 --> 00:04:13,090
this image model sitting around because obviously we want to eventually somehow get it on the screen
58
00:04:13,090 --> 00:04:13,750
of our device.
59
00:04:14,140 --> 00:04:16,079
It's a quick break and we'll see you in just a minute.
5900
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.