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 added a new instance variable to our image list class, but now we see this
error message that says essentially all instance fields must be final.
So the error message is really complaining about this images property that we just added to the image
list in this section.
We're going to talk about a little quick side topic once we learn about this quick side topic will then
come back over to the image list and talk about how the site topic applies over here.
So site topic, I'm going to pull up and dart dart pad very quickly and we'll talk about a new piece
of dirt syntax.
So it's at this point in this course, we've been defining all of our variables by using the VA keyword.
So we've been saying stuff like VA, my name equals Steven or VA.
My number equals whatever.
Right?
Well, it turns out that when we declare a variable with the keyword of VA right here, we're declaring
a certain type of variable or perhaps would be more appropriate to say we are declaring a variable that
is going to be treated in a very specific way by darte.
When we make a variable with the VA keyword, we are telling Dart that we want to declare a variable
with this name that can be reassigned at some point in time in the future.
So after I declare my name right here, I can easily say my name now equals something else where I can
say my number now equals some other number and there's no issue here whatsoever.
So by using the VA keyword, we are declaring a variable that can change over time, it can be reassigned
at some point in the future.
There's another keyword that we can use to declare a variable.
And when we use this other keyword, it declares a variable that behaves a little bit differently.
So one other keyword that we can use to declare a variable is the final keyword when we declare a variable
with the final keyword, let's say a final name equals Steven actually final.
My name, just to be clear.
So when we use that final keyword, it's saying or it's telling D'Arte that we are never going to change
the assignment to this variable.
So after using final, I cannot change the assignment to my name.
So if I try to say my name is now blah, blah, blah, I'm going to see an error message that says that
I'm trying to modify a variable that has already been declared the.
So that in this case, we're not really seeing an error message right here just yet because it's having
a hard time keeping up.
If I click run, we will see the error message appear over here on the right hand side.
Yeah, there we go.
So it says that we are trying to essentially assign some property or assign a value to a variable that
was defined as being final.
So how does this relate to the error message we just saw back over here inside of our Ed?
When we create a stateless widget, remember we said that stateless widgets contain data that should
not change over time because when we create a stateless widget.
Flutter is going to create that thing and then throw it away every time it tries to render our application.
So every time we call the build method inside of our app dart file.
So this thing right here, we're going to be constantly creating new copies of the image list and throwing
them away over and over and over again.
So Flutter wants to make sure.
That you and I don't get it into our heads, that we can change the value of images right here because
in order to change images, we have to create an entire new instance of the image list widget.
So to fix that error message, we need to mark the images variable right here as being final and saying
this is the last value, this thing, it's never going to be changed at any point in time.
So we have to add the final keyword in front of the type declaration like so, and when I add that in
now that error message goes away, we still have the one complaining about the build method.
But we'll take care of that in just a moment.
So, again, any time we have a stateless widget and we try to define a instant's variable on it, we
must mark that variable as being final to say that we do not plan to ever change this variable at any
point in the future.
Now, moving forward, now that we've discussed this final keyword, we're going to be using the final
keyword at several other locations inside of our project, not just for Mirkin Fields as being final
inside of stateless widgets.
It turns out that using the final keyword is actually pretty good practice when you're writing out very
simple functions.
So, for example, back inside of our dirt file.
We can find our fetched image method right here.
We had declared response an image model right here, both with the VA keyword.
However, I think that you can agree with me that in no way, shape or form should we ever change the
assignment of response inside of the Thach image method.
If we do well, that might actually be a pretty big er, you know, if we say something like responses
now, a string or something like that.
So moving forward, you and I are going to define more and more variables that use the final key word
instead, and that's going to keep you and I from accidentally ever redefining variables when we don't
really need to now.
Right now, I'll just leave these as far to keep things unchanged.
But again, moving forward, we're going to see a lot more use of that final keyword.
OK, so we got one error message resolved.
Let's take a quick break and we'll continue in the next section.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.