Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,830 --> 00:00:06,170
In the last section, we finished up a quick aside on how we can work with Jason Data, we created that
2
00:00:06,170 --> 00:00:09,770
image model class we placed down here at the bottom of our dart at code.
3
00:00:10,560 --> 00:00:14,690
We're now going to flip back over to our code editor and we're going to make a new file that's going
4
00:00:14,690 --> 00:00:20,990
to house a image model class that we're going to create for our project once we get that class fit together,
5
00:00:21,290 --> 00:00:27,320
will then make our actual API request over to that Jason type code, fake API endpoint.
6
00:00:27,530 --> 00:00:32,030
We'll get our image lifescience the image model and we can figure out how to show it on the screen.
7
00:00:32,810 --> 00:00:35,690
So I'm going to get started by flipping back over to my code editor.
8
00:00:36,500 --> 00:00:41,660
I'm going to make a new file inside of a new folder that I'm gonna place inside of my SIRC directory.
9
00:00:42,020 --> 00:00:49,160
So inside of SC, I'm going to make a new folder called Models, and then inside there I'll make a new
10
00:00:49,160 --> 00:00:53,660
file called Image Underscore Model Dot Dart.
11
00:00:56,280 --> 00:01:01,160
So now inside of here, we're going to basically write out this same code we just saw over on dart pad,
12
00:01:01,650 --> 00:01:03,840
so I'll do class image model.
13
00:01:05,360 --> 00:01:12,860
It's going to have an ID that's going to be an integer type, I'll give it a string of Eurail in a string
14
00:01:12,860 --> 00:01:14,090
of title as well.
15
00:01:14,660 --> 00:01:17,690
Now, remember, I'm not making these property names up right here.
16
00:01:17,810 --> 00:01:23,690
These are the exact property names that are coming from the JSON that represents one of our images from
17
00:01:23,690 --> 00:01:24,870
that fake API.
18
00:01:25,460 --> 00:01:26,970
So here's it right here.
19
00:01:27,020 --> 00:01:28,390
It's always going to be an integer.
20
00:01:28,850 --> 00:01:33,920
We have the title of the image, which is a string, and we have the URL, which is a string as well.
21
00:01:36,220 --> 00:01:40,990
We could store the thumbnail, you, Earl, and album ID properties, but they're really just not relevant
22
00:01:40,990 --> 00:01:44,680
to what we're doing at all, so we're just going to completely ignore those other properties.
23
00:01:47,210 --> 00:01:52,890
So then inside of here, we'll first set up our constructor with the same name as the class, so I'll
24
00:01:52,910 --> 00:02:01,110
say image model and I will accept this ID, this DOT URL and this DOT title like so.
25
00:02:01,790 --> 00:02:08,539
So we now have the ability to create a new image model instance by directly supplying an ID, a neutral
26
00:02:08,600 --> 00:02:09,199
in a title.
27
00:02:10,699 --> 00:02:16,640
We're going to also add on our named constructor that will call from Jason.
28
00:02:18,920 --> 00:02:24,080
So we have the ability to create an image model instance, either by using this constructor or from
29
00:02:24,080 --> 00:02:30,110
JSON, so we're going to receive an argument into this named constructor right here that we'll call
30
00:02:31,100 --> 00:02:32,870
past Jason.
31
00:02:34,010 --> 00:02:41,810
And then from that pass, Jason, we will update the ID you and title properties, so I will say ID
32
00:02:42,080 --> 00:02:46,100
equals past Jason ID.
33
00:02:48,170 --> 00:02:52,460
I'll tell you, Earl of past, Jason Yoro.
34
00:02:53,450 --> 00:02:56,150
And I'll do title of past, Jason.
35
00:02:57,350 --> 00:02:59,330
Title look like so.
36
00:03:00,420 --> 00:03:02,620
OK, so that is pretty much it.
37
00:03:03,420 --> 00:03:05,660
Now, there's one quick thing I want to mention here.
38
00:03:06,120 --> 00:03:11,460
When you go and look at documentation around model classes like this that are meant to intercept Jason
39
00:03:11,460 --> 00:03:17,430
or take Jason data, you might see that the pass Jason argument right here to our name constructor will
40
00:03:17,430 --> 00:03:18,660
be annotated with a type.
41
00:03:19,090 --> 00:03:24,330
So technically, when we pass some Jason with that Jason Dot Decode function, the type that we get
42
00:03:24,330 --> 00:03:30,510
back is a map with type string and type dynamic.
43
00:03:32,230 --> 00:03:32,740
Like, so.
44
00:03:33,340 --> 00:03:39,460
So this is saying that you can call our name constructor from JSON with a map data structure and remember,
45
00:03:39,460 --> 00:03:43,940
maps are like JavaScript objects, Ruby hashes maps in Java or similar.
46
00:03:44,710 --> 00:03:50,200
This is saying that we have a map with keys that are strings and values that are dynamic.
47
00:03:50,230 --> 00:03:52,330
So we don't really know what their values are.
48
00:03:53,230 --> 00:03:56,770
So when you look at documentation, you'll sometimes see this type annotation right here.
49
00:03:56,770 --> 00:03:58,060
And it's definitely worth putting on.
50
00:03:58,750 --> 00:04:03,850
One of the quick note that to throw out there is that we used a kind of long form constructor right
51
00:04:03,850 --> 00:04:04,150
here.
52
00:04:04,510 --> 00:04:09,760
We can technically write a little bit more abbreviated structure for this name constructor.
53
00:04:09,790 --> 00:04:11,140
I'll show it to you very quickly.
54
00:04:11,380 --> 00:04:16,779
I do encourage you to use the longer form just because it's a lot more clear what's going on.
55
00:04:17,079 --> 00:04:21,130
But I'll show you the shortened form just in case you're curious, because you will sometimes see it
56
00:04:21,130 --> 00:04:22,180
in documentation.
57
00:04:22,950 --> 00:04:23,290
All right.
58
00:04:23,300 --> 00:04:25,300
So I encourage you to not write this code out.
59
00:04:25,310 --> 00:04:29,980
I'm just going to very quickly write it out for you so we could have alternatively.
60
00:04:31,920 --> 00:04:39,450
Put down a colon and then wrote out it could put down a colon after the closing parentheses over here,
61
00:04:40,050 --> 00:04:47,850
and then we could have removed all these semicolons and instead put a comma after each one, a semicolon
62
00:04:47,850 --> 00:04:50,710
after the very last one, and then remove that semicolon.
63
00:04:51,450 --> 00:04:53,040
So then if I save this file.
64
00:04:53,070 --> 00:04:53,730
Yeah, there we go.
65
00:04:54,450 --> 00:04:59,940
So what you see right here and right here, totally identical syntax.
66
00:04:59,940 --> 00:05:01,290
Both work just fine.
67
00:05:01,650 --> 00:05:04,700
But personally, I think this is just way more clear.
68
00:05:04,860 --> 00:05:07,800
It's still like the same number of characters, right?
69
00:05:07,800 --> 00:05:09,210
It's the same amount of space.
70
00:05:09,600 --> 00:05:14,550
But in this case, you don't have to worry about like comma, comma, semicolon, and you don't have
71
00:05:14,550 --> 00:05:15,950
to worry about the colon as well.
72
00:05:16,200 --> 00:05:20,040
So the syntax I showed you, I think is really clear and very obvious.
73
00:05:20,490 --> 00:05:25,290
You're going to see the syntax in some documentation, but I think it's just a little bit harder to
74
00:05:25,290 --> 00:05:26,190
wrap your head around.
75
00:05:26,790 --> 00:05:27,060
All right.
76
00:05:27,060 --> 00:05:29,460
So I am going to delete that alternate approach.
77
00:05:30,410 --> 00:05:33,350
OK, so that's it, we've got our image model put together.
78
00:05:33,380 --> 00:05:34,730
Let's take a quick pause right here.
79
00:05:34,910 --> 00:05:38,210
Come back to the next section and we're going to figure out how to make our API request.
80
00:05:38,340 --> 00:05:42,050
That's going to get some Jason data that we're going to load up into our image model.
81
00:05:42,410 --> 00:05:43,810
So I'll see you in just a minute.
7958
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.