Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,180 --> 00:00:05,200
Passing our function down to the answer
2
00:00:05,200 --> 00:00:05,750
buttons
3
00:00:05,740 --> 00:00:11,420
works. As a next step, I want to make sure that we show some meaningful text here instead of always answer
4
00:00:11,420 --> 00:00:12,010
1
5
00:00:12,140 --> 00:00:16,740
and as a little stylistic thing, I want to adjust the text color and
6
00:00:16,790 --> 00:00:22,160
we can do this by setting the text color argument on the RaisedButton and there, we can set this to
7
00:00:22,160 --> 00:00:28,970
colors.white, again colors is this utility class which groups a bunch of predefined color codes so
8
00:00:28,970 --> 00:00:35,870
to say and I assign this color code to text color which will unsurprisingly color this text white.
9
00:00:35,870 --> 00:00:40,010
But now let's make sure we have different texts here which we pass down
10
00:00:40,010 --> 00:00:48,080
and for that, our question here now has to become a bit more complex because now a question should not
11
00:00:48,080 --> 00:00:49,660
just be a string,
12
00:00:49,700 --> 00:00:55,850
the question itself, it should also contain information about the available answers.
13
00:00:55,880 --> 00:01:01,940
Now of course as long as our question is just a string, we can't put any additional info in there other
14
00:01:01,970 --> 00:01:03,620
than the question text.
15
00:01:04,340 --> 00:01:10,850
So what we need now in here is a more complex object which can group multiple pieces of information
16
00:01:10,850 --> 00:01:16,550
together, the text for the question but also the texts for the answers
17
00:01:16,550 --> 00:01:19,220
and what could be used for that?
18
00:01:19,550 --> 00:01:27,140
We could create a new class which has all these features we need and use that class to create objects
19
00:01:27,140 --> 00:01:33,950
here and that would be a perfectly liable way of managing this, would be perfectly fine.
20
00:01:33,980 --> 00:01:39,230
However since you're also taking this course to learn a little bit about Dart, I'll actually show you
21
00:01:39,230 --> 00:01:45,860
a different data structure that's also built into Dart which can also be useful if you have relatively
22
00:01:45,860 --> 00:01:51,690
trivial data structures which yet are more complex than just some text
23
00:01:51,950 --> 00:01:53,930
and that would be a map.
24
00:01:53,930 --> 00:02:00,740
You create a map with curly braces or by using the map class like this
25
00:02:01,250 --> 00:02:02,990
but let's use the curly brace syntax.
26
00:02:03,020 --> 00:02:07,850
So it's a little bit like a list which you create with square brackets but a map now is not a list of
27
00:02:07,850 --> 00:02:11,910
values but instead a collection of key-value pairs.
28
00:02:11,930 --> 00:02:14,120
You have a key to identify a value,
29
00:02:14,120 --> 00:02:20,360
for example here, you could have the question text key and you put the key between quotes, double or
30
00:02:20,360 --> 00:02:21,190
single quotes,
31
00:02:21,200 --> 00:02:21,890
doesn't matter,
32
00:02:21,890 --> 00:02:23,170
just be consistent
33
00:02:23,420 --> 00:02:29,450
and then the value is assigned by adding a colon after the key and then you have your value, in this
34
00:02:29,450 --> 00:02:34,910
case it's also a string but your value could be anything, could be a number, could be another map, could
35
00:02:34,910 --> 00:02:35,980
be a list,
36
00:02:36,110 --> 00:02:39,780
really any value can be used in here.
37
00:02:39,800 --> 00:02:42,870
The key also doesn't have to be a string,
38
00:02:42,890 --> 00:02:48,380
you could also have a number as a key, like one but often you will have strings because then you have a
39
00:02:48,380 --> 00:02:54,380
very human readable way of accessing the different pieces of information in that map.
40
00:02:54,380 --> 00:03:00,890
So now, one question here in our list of questions is no longer a string but instead a map and that map
41
00:03:00,890 --> 00:03:06,620
right now has a question text but now it shouldn't just have a question text, it should also have a list
42
00:03:06,620 --> 00:03:13,010
of answers and therefore, I'll add a comma to add another key-value pair to this map and I'll name this
43
00:03:13,010 --> 00:03:13,880
key now
44
00:03:13,910 --> 00:03:19,580
answers. These key names of course are totally up to you and now answers won't be a string but instead
45
00:03:19,700 --> 00:03:20,690
a list,
46
00:03:20,690 --> 00:03:25,310
as I mentioned, your values in the map can be anything. In this list,
47
00:03:25,310 --> 00:03:32,360
I now want to have a list of answer texts which we can display and here we could have since I'm
48
00:03:32,360 --> 00:03:33,950
asking for the favorite color,
49
00:03:34,100 --> 00:03:37,700
we could have let's say black,
50
00:03:37,780 --> 00:03:43,570
we also could have red, green and white here,
51
00:03:43,570 --> 00:03:46,660
you could add more but I want to have four answers let's say
52
00:03:47,620 --> 00:03:57,260
and with that if we now reformat this, we have this map with a question text and with an answer in here.
53
00:03:57,260 --> 00:03:59,990
Now of course, I want to have more than one question in the quiz,
54
00:03:59,990 --> 00:04:09,290
so I'll duplicate this and also add my second question here as a question text in the second map here,
55
00:04:10,390 --> 00:04:16,720
remove that double quote at the end and then at the beginning and here my answer texts could be,
56
00:04:16,780 --> 00:04:23,830
since I'm asking for animals, here I could be asking for a rabbit,
57
00:04:26,560 --> 00:04:37,080
a snake, an elephant and let's say a lion and let's add one more question here by copying and pasting in
58
00:04:37,080 --> 00:04:41,220
this map one more time and here, I'll ask for
59
00:04:43,890 --> 00:04:52,930
who is your favorite instructor and I want to offer a couple of totally objective choices here
60
00:04:52,940 --> 00:04:54,640
because that could be Max,
61
00:04:54,680 --> 00:04:55,620
Max,
62
00:04:55,830 --> 00:04:57,710
Max or Max.
63
00:04:58,160 --> 00:04:58,530
Okay
64
00:04:58,580 --> 00:05:01,750
of course enter whatever you want here.
65
00:05:01,820 --> 00:05:04,160
So these are my three questions
66
00:05:04,220 --> 00:05:10,520
and now we're using a map here, which just like everything else, every other value, is of course based
67
00:05:10,520 --> 00:05:18,200
on an object, it's based on on the map class which is built into Dart, so map is a class built into Dart.
68
00:05:18,290 --> 00:05:23,110
This is just a shorthand way of creating it, just as you have square brackets for lists
69
00:05:23,270 --> 00:05:29,210
and it's perfect if you have more complex data which you want to manage as key-value pairs like we have
70
00:05:29,210 --> 00:05:35,270
it here, where you could create your own class and your own object but if it is just such a simple collection
71
00:05:35,270 --> 00:05:41,090
of key-value pairs, creating a custom class in object might be overkill, though you absolutely could do
72
00:05:41,090 --> 00:05:48,140
it of course but it might be overkill and therefore creating such a little map here on the fly kind
73
00:05:48,140 --> 00:05:50,420
of can be very nice and helpful.
7647
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.