All language subtitles for 26. Using Private Properties

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

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.