Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,110 --> 00:00:05,640
In the last section, we wrote a little bit more code into our image method right here, and that really
2
00:00:05,640 --> 00:00:10,590
represents the accumulation of quite a bit of learning that we did in the last few sections.
3
00:00:10,930 --> 00:00:12,030
So we're making the request.
4
00:00:12,030 --> 00:00:13,980
We've got the async Kuwait syntax in there.
5
00:00:14,190 --> 00:00:18,990
We're decoding our JSON and then we're turning that into an actual model instance.
6
00:00:19,650 --> 00:00:23,280
Now that we've got our image model, we need to figure out how we can actually get this thing on the
7
00:00:23,280 --> 00:00:24,270
screen of our device.
8
00:00:25,090 --> 00:00:29,730
The first thing I want to do is remind you that over time we're probably going to end up with multiple
9
00:00:29,730 --> 00:00:30,800
image models.
10
00:00:31,110 --> 00:00:36,390
Remember, every time the user presses this button, we're going to fetch one additional image model
11
00:00:36,660 --> 00:00:39,590
and we want to render out a list of all those on the screen to the user.
12
00:00:40,320 --> 00:00:45,720
So I think that we should create a list instance variable tied to our app state widget right here.
13
00:00:46,450 --> 00:00:48,360
It'll be a list data type.
14
00:00:48,510 --> 00:00:52,320
And every time we create a new image model, we will add it to that list.
15
00:00:52,860 --> 00:00:58,890
We can then figure out how we can create one of these little image looking things right here for every
16
00:00:58,890 --> 00:01:01,170
image model that we have added to our widget.
17
00:01:02,260 --> 00:01:03,160
So to get started.
18
00:01:04,300 --> 00:01:08,890
I'm going to come back over to my app widget and I'm going to create a new variable in here that's going
19
00:01:08,890 --> 00:01:12,850
to be a list that holds records of type image model.
20
00:01:13,390 --> 00:01:18,760
So I will write out list by opening, closing less than greater than signs.
21
00:01:19,360 --> 00:01:22,930
And every element inside of my list is going to be an image model.
22
00:01:23,620 --> 00:01:28,840
And I will call this variable about images and we'll start it off as an empty list like so.
23
00:01:30,140 --> 00:01:36,470
So now inside of each image, every time we create a new image model, I'll do images dot ad.
24
00:01:37,410 --> 00:01:38,880
Image model like so.
25
00:01:40,240 --> 00:01:42,730
So now the images list is going to grow over time.
26
00:01:43,960 --> 00:01:45,400
All right, so that looks pretty good.
27
00:01:46,710 --> 00:01:52,530
Now, Leslie, I want to mention here is that clearly every time that we are adding a new record to
28
00:01:52,530 --> 00:01:59,340
the image model right here, we absolutely expect to see our app state widget try to re render itself
29
00:01:59,340 --> 00:02:02,040
and probably display the new image on the screen.
30
00:02:02,700 --> 00:02:05,860
So that goes back to a topic that we discussed a little bit ago.
31
00:02:06,270 --> 00:02:07,920
Let's go find the diagram for that.
32
00:02:08,610 --> 00:02:09,449
Where is it?
33
00:02:10,360 --> 00:02:11,039
Uh.
34
00:02:11,730 --> 00:02:12,270
Uh.
35
00:02:13,300 --> 00:02:13,750
Here we go.
36
00:02:15,100 --> 00:02:20,920
So we had said that when we were refactoring from a stateless widget to a stateful widget, any time
37
00:02:20,920 --> 00:02:27,130
our widget state classis data changes, we need to call this set state method in order to get our widget
38
00:02:27,130 --> 00:02:27,730
to update.
39
00:02:28,570 --> 00:02:34,360
So right here where we are adding some new information to an instance variable inside of our app state
40
00:02:34,360 --> 00:02:39,470
widget, we clearly want to see this widget render itself on the screen of our device.
41
00:02:40,000 --> 00:02:43,660
So in order to make that happen, I'm going to wrap the images.
42
00:02:43,660 --> 00:02:47,070
Don't add line right here with a call to that set state function.
43
00:02:47,650 --> 00:02:49,270
So I will say set state.
44
00:02:50,330 --> 00:02:56,810
I'm going to pass in a function to this thing and then I'm going to add the images that add statement
45
00:02:56,810 --> 00:02:58,160
inside of their legs, so.
46
00:03:00,510 --> 00:03:02,430
So now whenever we call image.
47
00:03:03,690 --> 00:03:09,930
Make our requests pass that, Jason, add the image to the images list and then inform our outstate
48
00:03:09,930 --> 00:03:14,010
widget that we've just made some change and it needs to re render itself on the screen.
49
00:03:15,340 --> 00:03:21,310
So I think this looks good, maybe the last thing we need to now do is make sure that whenever we built
50
00:03:21,310 --> 00:03:24,150
this widget, we have some widget inside of here.
51
00:03:24,490 --> 00:03:29,410
So inside the build method, that's going to iterate over the list of all the image models we have and
52
00:03:29,410 --> 00:03:31,510
try to display each image on the screen.
53
00:03:32,020 --> 00:03:35,140
So this is going to be an exercise in basic list building.
54
00:03:35,530 --> 00:03:36,640
So let's take a quick pause.
55
00:03:36,640 --> 00:03:39,400
We'll come back to the next section and figure out how to build that list.
56
00:03:39,700 --> 00:03:41,010
So I'll see you in just a minute.
5397
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.