Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,300 --> 00:00:05,220
So now that we're pretty much done with the design of our user interface, there's only one thing that
1
2
00:00:05,220 --> 00:00:08,380
looks a little bit different from our original intention.
2
3
00:00:08,400 --> 00:00:15,420
It's the fact that the dice images should probably be in the center of the screen. And it should have a
3
4
00:00:15,420 --> 00:00:18,750
little bit of padding from the edges.
4
5
00:00:18,750 --> 00:00:21,420
Let's go ahead and implement those changes.
5
6
00:00:21,420 --> 00:00:28,320
Previously whenever we needed to embed a widget inside another widget, or add another widget somewhere
6
7
00:00:28,320 --> 00:00:36,810
into the widget tree, we've always taken our widget out say, remove our row widget here and all its children
7
8
00:00:37,380 --> 00:00:44,880
and instead return something like a center widget, which has a child which is now going to be the row
8
9
00:00:44,880 --> 00:00:52,890
widget. And you can see that when I put that in there, and I delete all the parts I don't need, and I move
9
10
00:00:52,890 --> 00:00:58,530
that semicolon down to the closing bracket for center, and add a comma there,
10
11
00:00:58,920 --> 00:01:06,380
then you can see that this does what I need to do, which is to move our row into the center of the screen.
11
12
00:01:06,540 --> 00:01:11,970
But that was kind of fiddly and especially messing around with the semicolons and commas.
12
13
00:01:12,150 --> 00:01:15,870
You're bound to have issues eventually down the road.
13
14
00:01:15,870 --> 00:01:23,290
So I want to show you a much easier way, and you're going to be using this a lot once you discover it.
14
15
00:01:23,310 --> 00:01:30,000
Now it's important to first show you what the pain points are, which is why I've kept this in the secret
15
16
00:01:30,000 --> 00:01:31,560
bag until now.
16
17
00:01:31,560 --> 00:01:34,350
Let's say that we want to do the same thing as we did before.
17
18
00:01:34,350 --> 00:01:41,370
We want to move our row from the top left corner of the body, which is this part below the app bar, all the
18
19
00:01:41,370 --> 00:01:43,980
way to take up the center of the space.
19
20
00:01:43,980 --> 00:01:47,210
So we need a center widget around our row.
20
21
00:01:47,400 --> 00:01:53,310
And essentially, what we want to do, is to insert a center widget at this point here.
21
22
00:01:53,340 --> 00:02:00,720
So below the scaffold but above the row, so that all of the row and the expanded widgets and dice images
22
23
00:02:01,080 --> 00:02:10,750
are contained inside this center widget. So the widget that we want to embed inside a new widget is the
23
24
00:02:10,750 --> 00:02:11,450
row.
24
25
00:02:11,800 --> 00:02:18,100
And instead of cutting it out and moving it somewhere else before replanting it back here, we can simply
25
26
00:02:18,160 --> 00:02:19,050
select it.
26
27
00:02:19,120 --> 00:02:27,340
So put our cursor anywhere on the word row, and then go into our Flutter outline and we can click on
27
28
00:02:27,580 --> 00:02:29,400
this button right here.
28
29
00:02:29,520 --> 00:02:35,680
And if you hover over it for long enough, it'll tell you this button will center the widget that you've
29
30
00:02:35,680 --> 00:02:37,390
currently got selected.
30
31
00:02:37,780 --> 00:02:43,720
So in the outline you can see we've got the rows selected. When you click on it in the code,
31
32
00:02:43,720 --> 00:02:46,750
It will move the selection in the tree.
32
33
00:02:46,750 --> 00:02:52,030
But this is what we want to select and we're going to click on this button, and it will automatically
33
34
00:02:52,300 --> 00:02:59,590
add that center widget around the row, which is almost like wizardry.
34
35
00:02:59,590 --> 00:03:05,600
The beauty of this is that it'll move the semicolons or commas as needed.
35
36
00:03:05,600 --> 00:03:11,640
It'll add that child property and we don't have to do anything other than just click on a button.
36
37
00:03:11,640 --> 00:03:19,150
Now, there's many ways of actually getting Flutter to embed or add, and there's other things that we can
37
38
00:03:19,150 --> 00:03:20,740
do automatically as well.
38
39
00:03:20,740 --> 00:03:28,420
For example, if we wanted to embed our, I don't know, row inside a column, we could simply click on this 'wrap
39
40
00:03:28,420 --> 00:03:32,770
with column' button, and now our row is inside a column.
40
41
00:03:32,770 --> 00:03:37,990
I'm going to hit COMMAND + Z to go back before we get really lost in messing around with all the buttons.
41
42
00:03:37,990 --> 00:03:45,370
But, another way of doing this is you can simply select the element inside the widget tree here, and you
42
43
00:03:45,370 --> 00:03:51,430
can right click on it to send to the widget or add padding or wrap with column, wrap with row, wrap with
43
44
00:03:51,430 --> 00:03:52,840
container.
44
45
00:03:52,840 --> 00:03:57,150
And these are pretty much all of the most common things that you will want to do.
45
46
00:03:57,700 --> 00:04:04,030
But sometimes, you might want to do something that's a little bit more specific, such as what if we wanted
46
47
00:04:04,030 --> 00:04:08,210
to remove this expanded widget out of the tree.
47
48
00:04:08,440 --> 00:04:13,980
But I wanted to leave the image widget where it is. Essentially,
48
49
00:04:14,030 --> 00:04:21,740
I want to simply pluck that expanded widget out of the tree, and make the dice1 image a child of the
49
50
00:04:21,740 --> 00:04:26,820
row, without having an expanded widget around it. Again,
50
51
00:04:26,830 --> 00:04:29,350
normally that would be really really painful.
51
52
00:04:29,410 --> 00:04:33,630
And over here you can't actually really do it when you right click, right?
52
53
00:04:33,640 --> 00:04:36,600
What I need is a delete widget.
53
54
00:04:36,640 --> 00:04:44,290
Now you can get access to that if you click in your code and you go over to that light bulb that shows
54
55
00:04:44,290 --> 00:04:44,730
up.
55
56
00:04:44,730 --> 00:04:50,420
And if you click on the dropdown list, you can see, oh we have more things that we can do.
56
57
00:04:50,620 --> 00:04:53,500
We can remove our widget.
57
58
00:04:53,500 --> 00:05:01,270
We can move our widget down, so that this one becomes the second child in the row, and it gets moved over
58
59
00:05:01,510 --> 00:05:05,830
to the right of the row. Or we can remove widget.
59
60
00:05:06,170 --> 00:05:11,560
And that achieves exactly what we were talking about which is removing the expanded widget from the
60
61
00:05:11,560 --> 00:05:16,330
tree, but leaving the image where it is inside the row.
61
62
00:05:16,360 --> 00:05:24,280
Now, I didn't actually want to do that because our design now looks like this. But I wanted to be able
62
63
00:05:24,280 --> 00:05:30,200
to show you what you can do by tapping into these so called intention actions.
63
64
00:05:30,370 --> 00:05:36,690
You can add padding, you can send to the widget, everything that we saw over here and there's more,
64
65
00:05:36,700 --> 00:05:37,450
right?
65
66
00:05:37,480 --> 00:05:43,600
For example, let me remove my expanded widget, and go back to the scenario where I wanted to wrap our
66
67
00:05:43,600 --> 00:05:50,170
image inside an expanded widget. Instead of cutting it out, moving it around, doing all sorts of complicated
67
68
00:05:50,170 --> 00:05:50,720
things,
68
69
00:05:50,860 --> 00:05:57,580
I could have just clicked on the light bulb and clicked on 'wrap with new widget' and it will wrap my widget
69
70
00:05:57,760 --> 00:06:01,300
inside a new widget at that position in the tree.
70
71
00:06:01,300 --> 00:06:08,920
And now I get to type 'expanded' and it does exactly the same thing. My widget is now inserted into the
71
72
00:06:08,920 --> 00:06:18,220
tree, and my image now looks as it should. The light bulb will show up
72
73
00:06:18,220 --> 00:06:23,990
once you click on something that has these intention actions. So namely, in Android Studio,
73
74
00:06:24,000 --> 00:06:29,950
if you have the dark mode enabled, it'll be something yellow, like center or row or expanded. One of the
74
75
00:06:29,950 --> 00:06:30,390
widgets
75
76
00:06:30,400 --> 00:06:37,750
basically. If you wanted to pull up that menu without needing your mouse, then you can move your cursor
76
77
00:06:37,780 --> 00:06:44,190
to the widget that you want to embed or delete or do something to, and then hold down OPTION or ALT
77
78
00:06:44,380 --> 00:06:46,000
and hit ENTER.
78
79
00:06:46,000 --> 00:06:52,690
So it'll be ALT + ENTER for Windows, and OPTION + ENTER for Mac. and then you pull up that menu anyways and
79
80
00:06:52,690 --> 00:06:59,680
this will be a really fast way of adding padding, of removing widgets, of doing all of these intention
80
81
00:06:59,680 --> 00:07:00,340
actions.
81
82
00:07:00,820 --> 00:07:07,960
And actually, what I want to do right now, is to add some padding around our dice images, so our expanded
82
83
00:07:08,020 --> 00:07:11,130
widgets, in order for it to look a bit more like this.
83
84
00:07:11,140 --> 00:07:16,850
So there's a bit of space in between the images and also from the sides of the screen.
84
85
00:07:17,050 --> 00:07:25,570
So using the intention actions menu that we just talked about, can you insert 16 pixels of padding around
85
86
00:07:25,660 --> 00:07:32,980
both dice, so that they end up looking like this. Pause video, and try and complete this challenge.
86
87
00:07:36,830 --> 00:07:41,000
We've got our two image widgets, which we need padding around.
87
88
00:07:41,120 --> 00:07:47,150
So all we need to do, is to put our cursor onto the widget that we need to pad, and we're going to hold
88
89
00:07:47,150 --> 00:07:53,390
down OPTION or ALT, and hit ENTER. And then we're gonna select add padding. And automatically, a whole
89
90
00:07:53,390 --> 00:07:55,290
bunch of code gets written for us.
90
91
00:07:55,450 --> 00:08:00,640
And it's so simple that you could almost just hit TAB all day long, and get all your code written.
91
92
00:08:00,640 --> 00:08:07,100
Now by default, when we insert padding it adds eight pixels of padding around all four edges, but that's
92
93
00:08:07,100 --> 00:08:08,080
not enough for us.
93
94
00:08:08,090 --> 00:08:10,680
So we're going to change that to 16.
94
95
00:08:10,880 --> 00:08:14,140
And now, we have our images nicely padded.
95
96
00:08:14,390 --> 00:08:20,910
And I can do the same thing to my other image. Add padding and change it to 16.
96
97
00:08:21,200 --> 00:08:26,660
So now that we've achieved the look that we want, we're finally ready to start adding functionality to
97
98
00:08:26,660 --> 00:08:27,380
our app.
98
99
00:08:27,410 --> 00:08:30,200
So for all of that and more, I see on the next lesson.
11425
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.