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
Passing our function down to the answer
buttons
works. As a next step, I want to make sure that we show some meaningful text here instead of always answer
1
and as a little stylistic thing, I want to adjust the text color and
we can do this by setting the text color argument on the RaisedButton and there, we can set this to
colors.white, again colors is this utility class which groups a bunch of predefined color codes so
to say and I assign this color code to text color which will unsurprisingly color this text white.
But now let's make sure we have different texts here which we pass down
and for that, our question here now has to become a bit more complex because now a question should not
just be a string,
the question itself, it should also contain information about the available answers.
Now of course as long as our question is just a string, we can't put any additional info in there other
than the question text.
So what we need now in here is a more complex object which can group multiple pieces of information
together, the text for the question but also the texts for the answers
and what could be used for that?
We could create a new class which has all these features we need and use that class to create objects
here and that would be a perfectly liable way of managing this, would be perfectly fine.
However since you're also taking this course to learn a little bit about Dart, I'll actually show you
a different data structure that's also built into Dart which can also be useful if you have relatively
trivial data structures which yet are more complex than just some text
and that would be a map.
You create a map with curly braces or by using the map class like this
but let's use the curly brace syntax.
So it's a little bit like a list which you create with square brackets but a map now is not a list of
values but instead a collection of key-value pairs.
You have a key to identify a value,
for example here, you could have the question text key and you put the key between quotes, double or
single quotes,
doesn't matter,
just be consistent
and then the value is assigned by adding a colon after the key and then you have your value, in this
case it's also a string but your value could be anything, could be a number, could be another map, could
be a list,
really any value can be used in here.
The key also doesn't have to be a string,
you could also have a number as a key, like one but often you will have strings because then you have a
very human readable way of accessing the different pieces of information in that map.
So now, one question here in our list of questions is no longer a string but instead a map and that map
right now has a question text but now it shouldn't just have a question text, it should also have a list
of answers and therefore, I'll add a comma to add another key-value pair to this map and I'll name this
key now
answers. These key names of course are totally up to you and now answers won't be a string but instead
a list,
as I mentioned, your values in the map can be anything. In this list,
I now want to have a list of answer texts which we can display and here we could have since I'm
asking for the favorite color,
we could have let's say black,
we also could have red, green and white here,
you could add more but I want to have four answers let's say
and with that if we now reformat this, we have this map with a question text and with an answer in here.
Now of course, I want to have more than one question in the quiz,
so I'll duplicate this and also add my second question here as a question text in the second map here,
remove that double quote at the end and then at the beginning and here my answer texts could be,
since I'm asking for animals, here I could be asking for a rabbit,
a snake, an elephant and let's say a lion and let's add one more question here by copying and pasting in
this map one more time and here, I'll ask for
who is your favorite instructor and I want to offer a couple of totally objective choices here
because that could be Max,
Max,
Max or Max.
Okay
of course enter whatever you want here.
So these are my three questions
and now we're using a map here, which just like everything else, every other value, is of course based
on an object, it's based on on the map class which is built into Dart, so map is a class built into Dart.
This is just a shorthand way of creating it, just as you have square brackets for lists
and it's perfect if you have more complex data which you want to manage as key-value pairs like we have
it here, where you could create your own class and your own object but if it is just such a simple collection
of key-value pairs, creating a custom class in object might be overkill, though you absolutely could do
it of course but it might be overkill and therefore creating such a little map here on the fly kind
of can be very nice and helpful.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.