Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bihari
Bosnian
Breton
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hmong
Hungarian
Icelandic
Igbo
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tatar
Telugu
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we got a better idea of how to work with Jason data that we fetch from some remote
API, but the very end, I mentioned how with Dart we like to have a good idea of the type of data that
we are working with when we retrieve some JSON from some endpoint.
We really don't know what the values that we're going to get back inside that, Jason, are.
So one very common thing that we do is create model classes to give darte a better idea of the type
of data that we expect to get back from this JSON API.
So to get started in creating a model class will first define a class at the bottom of this file.
I'm going to call my class image model because it is essentially a class that's going to model all the
different properties of an image.
Then the two different instance variables that I will assign to this class are going to be the same
instance, variables that are contained inside of my JSON.
So I care about this property.
You are are right here and this is property right here.
You, Earl, is supposed to be a string and it over here is supposed to be an integer.
So I'm going to add an instance variable of Int for ID and for string.
I'll put in a Eurail.
So now we can add in a constructor function that will take in some ID and some URL and create a new
instance of this image model that we can work with.
So I will define my constructor function.
Remember, we can do that by defining a function inside the class with an identical name to the class
itself.
I'll put a semicolon at the end of the line and then we can accept inside of here this dotted as the
first argument in this URL as the second argument.
So now, rather than doing the print statement up here.
I can try to make a new image model instance with a new image model, and then for the first argument,
I will pass in an ID, so I will say past Jason and I'll use the square brackets ID.
And then for the second argument, I'll pass in that you out so fast, Jason, you, Earl.
All right.
I know this line is a little bit tight right there.
So I'm going to zoom out for just a moment so you can see the entire segment of code on one line.
There we go.
So now when we get back, this map of past JSON data will create a new image model instance passing
in our ID and the URL, now that we've got the image model right here, Darte knows exactly what properties
and what types of values it should expect to see on this image model.
So now we could print out, say, image model and we do not have to access our ID or our URL with the
bracket notation anymore.
We can simply use a print image model ID and if we run this, we will again see one appear up here.
There we go.
And of course, I can do your URL as well.
And I get back the out.
OK, I'm going to zoom in just one more time and we're going to look at one additional improvement that
we can make to this.
All right, so nice and big again, so you can see the code more easily.
So all the kids we have right now definitely works, and it definitely gives start a better idea of
the different properties that we expect to get back from our Jason and their different types.
However, you'll notice that whenever we create an instance of the image model right here, we have
to do this very laborious practice of referencing the past, Jason, and then trying to reference some
particular property to pass in.
So I want to make one more improvement to this, and I want to try to make creation of an image model
like we are right here a little bit easier and straightforward than it is right now.
So let's take one more brief pause.
We'll come back to the next section and we'll figure out how we can improve this line of code right
here to be a little bit more concise than it currently is.
So quick break and I'll see you in just a minute.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.