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
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
Russian
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
So we learned about stateful widgets, the other type of widget you can create in Flutter which differs
from the stateless widget in that it can manage internal data.
Well you could do that in a stateless widget too, you can do that in any Dart class after all
but in a stateful widget if you manage that internal data actually in a state object then which is connected
to the stateful widget, you can update this in a way that it's picked up by Flutter and that UI also
updates.
That's nice,
now let's dive a little bit deeper into Dart at this point,
let me show you one alternative syntax here which I would recommend using because it is a common pattern
and a common practice and you'll see it in other official examples and we'll also use it throughout the
rest of the course. In Dart,
you can have variables on classes like question index and you call these variables properties then and
you can have functions and classes and they are called methods then.
Now that's not new.
Now in Dart, you also can put your code into more than just one file,
we only used one file thus far but actually, I'm already importing something from that material.dart
file which is exposed by the Flutter package.
Now as a default in Dart, every file is its own enclosed ecosystem you could say, it's own so-called
library which can be a confusing name because we have that lib folder and it makes up a a bigger library
but in the end, every file in that folder is its own mini library.
These files can still work together with the help of import statements but you can control what can
be imported and what can be accessed in another file
and for example, you might want to restrict that this state object can be used and changed from inside
another file.
Now we only have that file here, right
but we'll soon add more files and then we want to make sure that we can maybe use our widget in other
files because we are for example also using the MaterialApp or the scaffold widgets which we get from
material.dart but in these widgets, we might not want to grant access to all the properties that are
in there or to this class, we might not want to grant access at all from inside other files because the
only thing that should use this class is the MyApp class here which needs the MyAppState class to
create that state.
Now of course, we as a developer, we are writing our own code and we can simply not use that class anywhere
else and we're fine
but if you are working in a bigger team or if you are sharing your application with other developers, then
you might want to put some protection into place so that the MyAppState can't be used or manipulated
from outside this file because if it could be manipulated from outside, then maybe you could change
question index from inside another file and that wouldn't be picked up by that widget correctly and your
app might therefore get out of sync or you might introduce weird bugs. Now to inform Dart that this
MyAappState class should only be usable from inside the main.dart file,
so from inside the file where it's defined, you add a leading underscore in front of the name and of course
you also have to add that in all the places where you use that name.
Now this might look like a cosmetic thing but actually, that leading underscore is a special syntax
in Dart and it turns this class which normally is a public class, which means it can be used in
any file which imports the main.dart file, this turns it from a public into a private class and now
MyAppState is a class that can only be used inside the main.dart file,
so in our case only in that MyApp class here. And that's what I want because since the state works together
with this class, it should really only be usable inside the same file
where the MyApp class lives.
So that is a common syntax you see
and on the same page, this variable and this method should also only be accessible from inside that file.
Hence we can add an underscore in front of question index and then also again in all the places where
we reference question index to signal that this should be a private property of this class here,
which means we can't access it from anywhere else in our project and let us do the same for this answerQuestion
function or method as it is then called. Let's add an underscore in front of it and then also
add an underscore here. Again, this is basically a convention I'm following here,
however it's not just a cosmetic change, it really has an impact,
it is a syntax understood by Dart.
It doesn't change the way our app works right now but now, we really ensure that MyAppState and all
the properties and methods in there can't be used from anywhere else
than inside this file and that is really important.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.