Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,410 --> 00:00:06,850
I'm here in a brand new Flutter project, just a bit cleaned up,
2
00:00:06,850 --> 00:00:12,640
I removed all the comments and I converted this homepage widget into a stateless widget and you find
3
00:00:12,650 --> 00:00:17,460
this main.dart file attached to this video in case you want to replace yours with it.
4
00:00:17,500 --> 00:00:23,200
I have no other widgets in this project right now, I haven't added any custom widgets, I haven't added
5
00:00:23,290 --> 00:00:23,740
anything,
6
00:00:23,740 --> 00:00:30,430
this is my basic setup and now the goal is to get started and we'll basically build this application
7
00:00:30,430 --> 00:00:36,730
as I just sketched it out and we'll add new widgets as we need them or dive into the widgets Flutter
8
00:00:36,760 --> 00:00:38,890
gives us as we need them. Now,
9
00:00:38,920 --> 00:00:42,430
what will we need to build this application?
10
00:00:42,430 --> 00:00:49,840
Remember that we had this chart area at the top and below that, we had a list of our transactions.
11
00:00:49,930 --> 00:00:57,160
So what we certainly have is at least two widgets sit next or above each other,
12
00:00:57,160 --> 00:01:00,320
we have that chart and below that, a list of transactions,
13
00:01:00,400 --> 00:01:04,680
that list of course also means that we have more than one item in there
14
00:01:04,840 --> 00:01:08,230
but we can take care about that in a separate step. For the moment,
15
00:01:08,290 --> 00:01:09,190
let's start basic
16
00:01:09,220 --> 00:01:14,200
and let's make sure that therefore on the body of our scaffold here, which is rendering that page of our
17
00:01:14,200 --> 00:01:15,840
app, that there
18
00:01:16,000 --> 00:01:19,530
we have a column because we will have two items in there.
19
00:01:19,580 --> 00:01:21,270
Hence we should add the children
20
00:01:21,310 --> 00:01:26,680
key here to the column and in there, I want to have these as a set, two arrays.
21
00:01:26,680 --> 00:01:33,140
Now for the moment, I'll add a card here and card is a built-in widget which is this pre-styled container
22
00:01:33,150 --> 00:01:40,630
I mentioned earlier, I'll add a card here to later hold my chart. For the moment the child which I add
23
00:01:40,660 --> 00:01:44,830
in the card, so the widget that is wrapped by that pre-styled container,
24
00:01:45,040 --> 00:01:51,760
that will be a text widget where I say chart, simply as a placeholder of course, we'll add a real chart
25
00:01:51,790 --> 00:01:53,630
there later.
26
00:01:53,800 --> 00:01:58,320
Now below that card, I want to have that list of transactions.
27
00:01:58,360 --> 00:02:08,310
So for now, let's add another card here where we say list of tx, tx for transactions simply. Let's save
28
00:02:08,320 --> 00:02:10,310
that and let's see if that works and for that,
29
00:02:10,320 --> 00:02:16,710
I'll start my app in without debugging, so I pressed the shortcut for this option here, start without
30
00:02:16,710 --> 00:02:19,740
debugging and I want to see whether that works.
31
00:02:19,740 --> 00:02:24,670
So let's wait for that to build and launch and with this launched, this is what we get.
32
00:02:25,800 --> 00:02:32,280
You might barely be able to see the card effect here, if you watch really close on your own screen probably,
33
00:02:32,510 --> 00:02:39,120
you'll see that the text is inside of a tiny container with a white background and a little drop
34
00:02:39,120 --> 00:02:40,270
shadow there.
35
00:02:40,290 --> 00:02:45,390
So this is certainly not the final look you want here but at least we have two widgets sit on top of
36
00:02:45,390 --> 00:02:46,380
each other.
37
00:02:46,620 --> 00:02:52,020
Now since we use that card and since the card is one of the more important base widgets Flutter gives
38
00:02:52,020 --> 00:02:52,380
you,
39
00:02:52,560 --> 00:02:57,920
let's see how we can make sure that this looks a bit better, that this also takes up more space
40
00:02:58,290 --> 00:03:04,530
and for that here, let's press control space and see what we can configure on the card. We could set the
41
00:03:04,530 --> 00:03:05,890
color, the background color,
42
00:03:05,890 --> 00:03:11,800
we can also set the elevation which simply is a double which controls how strong that drop shadow is.
43
00:03:11,800 --> 00:03:17,980
We can also add a margin which add some space around it and the other fields here aren't that helpful
44
00:03:17,980 --> 00:03:19,620
to us right now.
45
00:03:19,780 --> 00:03:25,510
So let's maybe go with elevation and set this to five and let's see how this changes things.
46
00:03:25,510 --> 00:03:32,140
Now we can see a bit of a more stronger drop shadow on that first widget or on this first card
47
00:03:32,260 --> 00:03:38,950
but what we haven't changed at all is the size. For this you have to know that the card by default
48
00:03:39,310 --> 00:03:42,340
assumes the size of its child.
49
00:03:42,340 --> 00:03:50,530
So if we want to change the size of that card here, then we need to change the size of child.
50
00:03:50,590 --> 00:03:56,510
Now text on the other hand is a widget which by default only takes as much space as this text needs
51
00:03:56,560 --> 00:04:02,130
and if you want to change the size of text, you need to change the size of its parent.
52
00:04:02,170 --> 00:04:04,190
So what can we do here
53
00:04:04,210 --> 00:04:09,040
since this card depends on the child and this text depends on the parent?
54
00:04:09,160 --> 00:04:12,430
We have a dependency which is kind of hard to break, right,
55
00:04:12,520 --> 00:04:15,880
how can we increase the overall size of the card?
56
00:04:15,890 --> 00:04:18,400
There are two ways of breaking that -
57
00:04:18,440 --> 00:04:23,300
one is that we wrap that text with a widget where we can set a size and
58
00:04:23,300 --> 00:04:28,720
we can do it with the refactoring shortcut which you can find in the key bindings in case you forgot it
59
00:04:28,790 --> 00:04:36,290
and there we can wrap the text with a container because container is the most universal styling positioning
60
00:04:36,290 --> 00:04:42,380
sizing widget you have. With a container, you can control almost anything when it comes to how something
61
00:04:42,380 --> 00:04:46,240
is sized or how something is aligned and styled,
62
00:04:46,550 --> 00:04:51,560
at least if we talk about things like background colors and so on and therefore, once I wrap the text
63
00:04:51,560 --> 00:04:57,680
with a container, we can use the fact that on the container we can set a width and we could set this to
64
00:04:57,680 --> 00:04:58,240
100
65
00:04:58,250 --> 00:05:03,560
and this means the container will now have the width of 100 device pixels which is a unit
66
00:05:03,590 --> 00:05:10,760
that always gives us the same size even on differently sized phones or devices.
67
00:05:10,760 --> 00:05:14,530
So now we can see that this container is a bit bigger,
68
00:05:14,600 --> 00:05:22,010
this becomes even clearer if I give that card a color, which is the background color, of let's say blue.
69
00:05:22,010 --> 00:05:25,700
If we do that, then we see it more clearly.
70
00:05:25,820 --> 00:05:32,690
So we can change the size of the card by increasing the size or in this case, the width of the child
71
00:05:32,720 --> 00:05:37,630
because now the child is a container, the direct child of the card is a container, on that
72
00:05:37,640 --> 00:05:44,000
we can set the width and therefore we make sure that the card no longer depends on the width of this
73
00:05:44,000 --> 00:05:50,430
text, which is just as big as it needs to be but instead on the width of the container which we can control.
74
00:05:50,480 --> 00:05:56,270
You could also set this to double.infinity which is a special value which means take as much width
75
00:05:56,300 --> 00:05:57,450
as you can get
76
00:05:57,620 --> 00:06:01,090
and here this means the container will take the entire width of the device
77
00:06:01,190 --> 00:06:07,250
since there is no other surrounding element or widget around our card that would restrict the overall
78
00:06:07,250 --> 00:06:09,180
width the card can take.
79
00:06:09,260 --> 00:06:11,980
So that is how we could break this.
80
00:06:11,990 --> 00:06:18,980
Another option would be that we don't wrap our text here in a container but the card. Again with the
81
00:06:18,980 --> 00:06:22,520
refactoring tool, we can add a container around card
82
00:06:22,520 --> 00:06:26,420
and now here we can also set the width to double.infinity
83
00:06:26,420 --> 00:06:33,920
for example. If we do that, we also have a card that takes the entire width and that has one important
84
00:06:33,920 --> 00:06:42,190
implication. The important implication is that card by default depends on the size of its child,
85
00:06:42,800 --> 00:06:52,580
unless you have a parent or a card like container, which has its own clearly defined width. This also
86
00:06:52,580 --> 00:06:55,440
means that column doesn't seem to be such a parent
87
00:06:55,490 --> 00:07:00,920
because when we just hit column around our card, the card didn't expand to take the full available width
88
00:07:01,280 --> 00:07:07,670
and indeed column is a widget which only takes as much width as its children need.
89
00:07:07,670 --> 00:07:12,520
Now with container, we give column a child that says please give me all the width I can get
90
00:07:12,650 --> 00:07:17,380
and it takes all the width it can get and therefore column sizes itself after that
91
00:07:17,400 --> 00:07:23,240
and also now takes the full available width because column always has the width of its broadest, of its
92
00:07:23,240 --> 00:07:31,580
widest child and card now does not take the width of its child but since it has a parent that sets a
93
00:07:31,580 --> 00:07:38,270
clearly defined size, card actually takes the parent as a measurement and takes the width of the parent.
94
00:07:39,200 --> 00:07:45,200
Now when you hear something like this the first time, it sounds like something that is incredibly hard
95
00:07:45,200 --> 00:07:50,530
to learn because it sounds like you have to remember all these combinations by heart,
96
00:07:50,600 --> 00:07:56,090
you have to remember that a card takes the child width unless there is a parent that sets a clearly defined
97
00:07:56,090 --> 00:08:03,320
width. Now two important points here - for one, you have the official docs and things like that are typically
98
00:08:03,500 --> 00:08:04,580
noted in there,
99
00:08:04,640 --> 00:08:10,020
so you can take you official docs to learn how widgets behave regarding their size
100
00:08:10,130 --> 00:08:16,680
and in addition and this is really the best advice I can give you, don't learn such things by heart, learn
101
00:08:16,820 --> 00:08:19,310
them by doing, experiment with things.
102
00:08:19,370 --> 00:08:24,020
If you have a card that doesn't have the size you want, start wrapping in a container,
103
00:08:24,020 --> 00:08:26,560
see what happens if you set a width or height there,
104
00:08:26,630 --> 00:08:28,190
start wrapping it with a column,
105
00:08:28,220 --> 00:08:33,930
see if that changes things, start wrapping the child of the card with a container and so on.
106
00:08:33,950 --> 00:08:40,610
So simply try things out because you will have no chance of learning these things by heart,
107
00:08:40,610 --> 00:08:43,630
there are way too many combinations and widgets to do that,
108
00:08:43,640 --> 00:08:48,350
that's also why I don't provide a cheat sheet with all possible combinations because that would be too
109
00:08:48,350 --> 00:08:50,140
many and too many to learn anyways,
110
00:08:50,180 --> 00:08:56,240
try such things out. Build a dummy application where you can simply play around with widgets just like
111
00:08:56,240 --> 00:09:01,760
we're doing it here and you will get a feeling for how you can combine widgets to get a certain result
112
00:09:02,120 --> 00:09:08,380
and also important in Flutter, there always is more than one way of getting a certain result, just as
113
00:09:08,380 --> 00:09:09,280
you see it here.
114
00:09:09,340 --> 00:09:13,270
We could have added the container around the card or inside the card, here
115
00:09:13,270 --> 00:09:16,450
the result is the same even though these are two different setups.
12982
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.