Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
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
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we spoke about how our jet function right here returns a future, we get back
a future because we have to wait for that request to be completed before we can actually access the
JSON data, the data that we get back.
So in order to work with the future that comes back, I'm going to use the async 08 syntax to do so.
I'll first mark the inclosing function as being async by putting the async keyword right after my argument
list.
Then in front of the git function, I will write out the await keyword, which tells Darte We need to
wait for the future that gets returned from the get function to be resolved before we can work with
the actual data.
So then after we await that, we're going to take whatever information we got back from the AP and assign
it to a new variable that we will call response.
And claps aside so we can see a little bit.
OK.
Now, one thing I want to point out here is, is that this response variable is not the actual JSON
data.
The response variable is an object that tells us a little bit about the entire response that came back
from that API.
So it contains status codes, headers, a lot of information about the actual request that or the response
that came back from the request that JSON data that we actually care about is nested inside of that
response object.
So now that we've at least got something that contains the Jason day that we care about, we can now
take that, Jason, we can decode it and then we can create a new image model instance from it.
So to get started with that, I'm going to first make sure that I import that image model class that
we created a couple of seconds ago.
Up at the top of the file, I'm going to import and remember, this is an important statement for a
file that you and I wrote, so we don't have to write out the package keyword or the package word here.
We just write out the path to the file that we want to get.
So we're currently inside of Apte Dart.
We're going to go into the models directory and then get the image underscore model, dot, dot, file.
So let's say models slash image.
Oops, image model that darts.
OK, so that works now down here.
Right after we take that response back, we're going to create a new image model instance, so say var
image model equals image model.
We want to take the JSON out of this response object and construct a new image model with it.
So I'm going to call the named constructor from Jason.
And I'm going to pass in that, Jason, from the response object, which is available on response dogsbody.
Now, before we leave it right here, we did miss one step.
Do you know what we missed?
Well, this right here is Jason Data.
It's still that raw, Jason.
So we first have to decode that, Jason, and we decode it by writing out Jason Dot Decode.
And we pass in the response body like so.
OK, now you'll notice that Jason is red right here, says Undefined, named Jason, that is because
we have not imported the package from the dark standard library that contains the JSON object.
So at the very top, I'm going to make sure that I also add on an import statement for darte colon convert.
The convert module that's part of the DART Senior Library is where we get that JSON object from.
So we now get back our response.
The actual raw JSON is available on response to body, we decode that, that gives us some pass JSON
and then we use the front JSON named constructor that we created to create a new image model instance.
And that's it.
That's pretty much it.
So we've now got our image model.
We've definitely made some progress.
But you'll notice that we're not really doing anything with image model just yet.
So let's take a quick pause right here and we'll talk about what we're going to now do that we have
this image model sitting around because obviously we want to eventually somehow get it on the screen
of our device.
It's a quick break and we'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.