All language subtitles for 11. Customising Widgets with Themes

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French Download
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 0 1 00:00:00,430 --> 00:00:00,730 All right. 1 2 00:00:00,750 --> 00:00:05,280 So our slider is looking beautiful and it's working beautifully as well. 2 3 00:00:05,670 --> 00:00:11,250 But for the keen eyed amongst you especially those who are designers, you will have noticed that there 3 4 00:00:11,250 --> 00:00:15,720 is a major difference between our slider and their slider. 4 5 00:00:15,720 --> 00:00:23,370 So one of the things is that they obviously have a white active side and a gray inactive side which 5 6 00:00:23,370 --> 00:00:30,680 is very easy to change because we can simply tap into that property, acticeColor, and change it to colors 6 7 00:00:30,730 --> 00:00:31,480 .white. 7 8 00:00:32,010 --> 00:00:35,820 But as soon as you do that you'll notice that the thumb color, 8 9 00:00:35,820 --> 00:00:43,200 so the color of the main toggle, also changes to the same color as the active track which is probably 9 10 00:00:43,200 --> 00:00:45,360 not what you want. 10 11 00:00:45,360 --> 00:00:52,950 Also if we look at this one, that holder or handle is much much bigger than what we have here which is 11 12 00:00:52,950 --> 00:00:54,020 a tiny one. 12 13 00:00:54,030 --> 00:00:58,170 So how do we make our design look more like this? 13 14 00:00:58,170 --> 00:01:04,530 Well if we go over to the documentation on the slider class, you can see that we have our usual properties 14 15 00:01:04,530 --> 00:01:08,280 which we change say the activeColor or the inactiveColor. 15 16 00:01:08,280 --> 00:01:14,550 And once you get to the bottom of the list, you'll notice that there's nothing that allows us to just change 16 17 00:01:14,850 --> 00:01:22,440 for example the size of that handle or the color of that handle without affecting this active track 17 18 00:01:22,440 --> 00:01:23,270 here. 18 19 00:01:23,280 --> 00:01:27,360 So what can we do beyond changing the properties of the slider? 19 20 00:01:27,960 --> 00:01:35,820 Well here's one way of customizing a Flutter widget to be more in line with exactly the design that 20 21 00:01:35,820 --> 00:01:36,740 you want. 21 22 00:01:36,900 --> 00:01:42,420 And if we read through this, you can see that to determine how the slider should be displayed, a slider 22 23 00:01:42,420 --> 00:01:51,060 uses the SliderThemeData available either from a SliderTheme widget or the ThemeData, a widget above 23 24 00:01:51,060 --> 00:01:57,330 it in the widget tree. Or you can override some of the colors but fine-grained control comes from the 24 25 00:01:57,330 --> 00:01:59,250 SliderThemeData. 25 26 00:01:59,250 --> 00:02:03,150 This is one of the things that we can do and we talked about themes before. 26 27 00:02:03,210 --> 00:02:10,170 So we already added a primary color to our app theme and we changed the scaffoldBackgroundColor across 27 28 00:02:10,200 --> 00:02:17,520 our app using this ThemeData. But we also said that we can have specific themes just for individual 28 29 00:02:17,520 --> 00:02:18,450 components. 29 30 00:02:18,550 --> 00:02:22,680 We can do that by embedding widgets inside another widget. 30 31 00:02:22,680 --> 00:02:29,880 So in this case we could embed it inside a SliderTheme and a SliderTheme has a property called data 31 32 00:02:30,420 --> 00:02:35,120 which is expecting something called a SliderThemeData. 32 33 00:02:35,130 --> 00:02:40,450 And once you hit ENTER, you can see that there's loads of things that you can set for example, the track 33 34 00:02:40,450 --> 00:02:47,480 height or the activeTrackColor the inactiveTrackColor, the thumbColor, all of these things. 34 35 00:02:47,580 --> 00:02:54,960 But in order to use a SlideThemeData like this, you would have to provide a value for everything because 35 36 00:02:55,170 --> 00:03:00,230 otherwise it will default to null, which is no color or no trackHeight. 36 37 00:03:00,360 --> 00:03:06,600 And if we had save right now, you can see that our slider is completely broken because none of these 37 38 00:03:06,600 --> 00:03:08,270 properties can be null, 38 39 00:03:08,280 --> 00:03:14,010 we had to provide a value. But what do you do if you're kind of happy with the default theme but you 39 40 00:03:14,010 --> 00:03:19,680 just want to tweak a couple of things without having to provide like 20 values and type out all this 40 41 00:03:19,680 --> 00:03:20,150 code? 41 42 00:03:20,640 --> 00:03:27,750 Well there's something that's really helpful across all of the widgets that Flutter has and it's something 42 43 00:03:27,750 --> 00:03:29,880 called .of. 43 44 00:03:29,880 --> 00:03:38,760 So we know that we already have a default SliderTheme. And we can tap into it and use a method called 44 45 00:03:38,910 --> 00:03:42,600 .of which will return the data, 45 46 00:03:42,690 --> 00:03:51,240 so that data property, from the closest SliderTheme in the given context. So we can write SliderTheme 46 47 00:03:51,600 --> 00:03:52,480 .of. 47 48 00:03:52,710 --> 00:03:58,280 And then we could provide a build context which comes from right over here. 48 49 00:03:58,830 --> 00:04:02,680 And this context is basically the current state of our app. 49 50 00:04:02,730 --> 00:04:05,610 It's how our app appears as it is. 50 51 00:04:05,610 --> 00:04:08,430 And that will include the current SliderTheme. 51 52 00:04:08,460 --> 00:04:17,190 So then if we say .of, we get a copy of what it looks like by default as it is. And then we can write 52 53 00:04:17,520 --> 00:04:25,530 again using that .copyWith which we saw previously where we copied over our dark theme and simply 53 54 00:04:25,710 --> 00:04:28,190 added a couple of changes. 54 55 00:04:28,290 --> 00:04:35,240 Now inside this copyWith, we can provide only the things that we want to change about the SliderTheme. 55 56 00:04:35,570 --> 00:04:39,000 And we don't have to create the entire thing from scratch. 56 57 00:04:39,060 --> 00:04:44,560 So the things that we want to change are for example the thumbShape. 57 58 00:04:44,670 --> 00:04:53,340 So instead of having it as the default size, we can change its size by saying that we want a round slider 58 59 00:04:53,340 --> 00:04:59,950 thumb shape which has a normal radius of 6 but we now want a larger radius. 59 60 00:04:59,960 --> 00:05:02,530 We're going to change it to maybe 15. 60 61 00:05:02,720 --> 00:05:11,900 And now you can see when I hit save, my thumb is a lot bigger. But notice that when I normally click on 61 62 00:05:11,900 --> 00:05:16,480 it, it has a little overlay a little transparent outer ring. 62 63 00:05:16,610 --> 00:05:23,120 And that's now gone because it's smaller than the normal fully opaque shape. 63 64 00:05:23,120 --> 00:05:29,900 Let's go ahead and add that and make it bigger as well. So we can add our overlay shape to be a round 64 65 00:05:30,380 --> 00:05:31,990 slider overlay shape. 65 66 00:05:32,090 --> 00:05:34,820 And by default, notice that it's 16. 66 67 00:05:34,820 --> 00:05:38,170 So just only one pixel bigger than our thumb shape. 67 68 00:05:38,510 --> 00:05:40,280 So let's make it a lot larger. 68 69 00:05:40,280 --> 00:05:42,660 Let's make it 30. 69 70 00:05:42,830 --> 00:05:53,450 And now when I click on this, you'll see my overlay animate and show up. It's looking pretty good now. 70 71 00:05:53,480 --> 00:05:55,310 What about our thumbColor? 71 72 00:05:55,640 --> 00:06:00,980 Well we can change that using the thumbColor property, and we're going to change it to our previous 72 73 00:06:01,250 --> 00:06:12,200 pink color which is a custom color that is going to be 0xFFEB1555. 73 74 00:06:12,440 --> 00:06:16,100 And that's that pink color that we have pretty much throughout our app. 74 75 00:06:16,160 --> 00:06:22,730 So let's hit save but our slider is not changing and it's because our activeColor is overriding that 75 76 00:06:22,730 --> 00:06:23,360 thumbColor. 76 77 00:06:23,780 --> 00:06:25,160 Let's get rid of it. 77 78 00:06:25,280 --> 00:06:30,600 So let's add instead an activeTrackColor, which is going to be colors.white. 78 79 00:06:30,680 --> 00:06:36,410 And now if we save, you'll notice that the left hand side is white, the right hand side is still gray 79 80 00:06:36,680 --> 00:06:44,860 and our thumb is pink. But when we click on it, it doesn't actually have an overlay color. 80 81 00:06:45,100 --> 00:06:48,330 So let's add a overlay color as well. 81 82 00:06:48,520 --> 00:06:54,790 And that's going to be the same color that we have for our thumbColor but we want it to have a little 82 83 00:06:54,790 --> 00:06:58,020 bit of a transparency. 83 84 00:06:58,280 --> 00:07:02,090 Now here's where the first part of my color comes in. 84 85 00:07:02,090 --> 00:07:08,030 Do you remember I mentioned that there's four components to the code here and it always starts out with 85 86 00:07:08,030 --> 00:07:09,090 0x 86 87 00:07:09,110 --> 00:07:13,210 and then it's two characters for the alpha or the transparency amount, 87 88 00:07:13,370 --> 00:07:20,120 and then it's red green and blue? What if we wanted to make it more transparent? 88 89 00:07:20,120 --> 00:07:23,740 Well we would modify these first two numbers. 89 90 00:07:23,870 --> 00:07:30,230 Now I quite liked how much transparency I was getting in the beginning when I had the default amount 90 91 00:07:30,260 --> 00:07:31,580 enabled. 91 92 00:07:31,580 --> 00:07:35,120 Now how can I find out what the default amount was? 92 93 00:07:35,120 --> 00:07:41,750 Well I could go into my slider theme by holding down my COMMAND on Mac or CONTROL on Windows, and I 93 94 00:07:41,750 --> 00:07:47,700 can click on the SliderTheme which takes me to my SliderTheme widget. 94 95 00:07:48,260 --> 00:07:56,720 And here I can search for that overlayColor property and you can see that if we go through all of them, 95 96 00:07:57,080 --> 00:08:04,100 you can see that the color is set as the primary color of the theme with a alpha amount that is something 96 97 00:08:04,100 --> 00:08:06,310 called an overlayLightAlpha. 97 98 00:08:06,620 --> 00:08:09,410 So let's try and find this overlayLightAlpha. 98 99 00:08:09,530 --> 00:08:14,900 So I've highlighted it and hit COMMAND + F or CONTROL + F and we're going to go through this document and 99 100 00:08:14,900 --> 00:08:16,970 you'll find it as a constant in here. 100 101 00:08:17,390 --> 00:08:22,810 So they've set the overlayLightAlpha as 0x29. 101 102 00:08:22,850 --> 00:08:26,300 So that gives us about 16% opacity they say. 102 103 00:08:26,780 --> 00:08:34,380 So now if we copy that over to our color and we replace the first four characters with 0x29, 103 104 00:08:34,380 --> 00:08:43,400 and we hit save, then you'll see that our thumb now has a overlay color of 16% opacity 104 105 00:08:43,670 --> 00:08:51,760 of that pinkish color that we've been using. And this now looks fully like the design that we see over 105 106 00:08:51,760 --> 00:09:00,290 here. So as I mentioned before, we can either keep our slider theme here or if you had multiple sliders 106 107 00:09:00,290 --> 00:09:08,540 in your app and you wanted a app wide slider theme, then you could copy your slider theme and paste it 107 108 00:09:08,750 --> 00:09:15,620 in here. And that would mean that all of the sliders across your app will have the same theme. 108 109 00:09:15,830 --> 00:09:21,250 But in our case, we only have one slider so it doesn't really matter where we have it. 109 110 00:09:21,300 --> 00:09:29,210 And I prefer having everything related to the same component all together in the same place. And to just 110 111 00:09:29,210 --> 00:09:35,030 keep it consistent, our inactiveTrackColor should probably also go in here. 111 112 00:09:35,060 --> 00:09:42,770 So we'll add the inactive track color and we'll paste this color over into here and we can delete it 112 113 00:09:42,770 --> 00:09:43,220 from here. 113 114 00:09:43,820 --> 00:09:50,270 So that means all of our styling is done in our theme and all of the properties or functionality is 114 115 00:09:50,270 --> 00:09:53,700 done inside the actual slider component. 115 116 00:09:53,720 --> 00:09:58,910 Now you can of course extract this widget if you wanted to use it in multiple places, but in our case 116 117 00:09:58,970 --> 00:10:00,230 we only really have one. 117 118 00:10:00,230 --> 00:10:05,440 So I'm just going to keep it in as it is. And also if you wish to, 118 119 00:10:05,450 --> 00:10:12,800 you can move all of these colors and themes into a constant and you could keep this main file a little 119 120 00:10:12,800 --> 00:10:16,330 bit cleaner if you wanted to. In this lesson, 120 121 00:10:16,330 --> 00:10:23,140 what I'm trying to show you is that anything is possible. Any design that you can dream up or your designer 121 122 00:10:23,140 --> 00:10:31,300 can dream up is fully possible either by creating your own widgets that combine different Flutter widgets, 122 123 00:10:31,870 --> 00:10:37,480 or whenever you're using Flutter widgets such as material components, you can always tap into the theme 123 124 00:10:37,690 --> 00:10:42,990 to be able to customize it further than just the properties that it normally comes with. 124 125 00:10:43,000 --> 00:10:49,810 So for example if you are using a alert dialog that comes from the material component, then you can take 125 126 00:10:49,810 --> 00:10:55,630 a look in the theme class then you see that there's a dialog theme which you can change. Or if you're 126 127 00:10:55,630 --> 00:11:02,260 using an app bar, you can change the app bar theme or the text theme or an icon theme or a tab bar theme. 127 128 00:11:02,260 --> 00:11:08,860 Basically all of these material components can be further fine tuned using the theme data. 128 129 00:11:08,860 --> 00:11:15,130 Now what if that is not enough? Because at the moment, we're using a slider because it looks very similar 129 130 00:11:15,130 --> 00:11:17,380 to the design that we're trying to achieve. 130 131 00:11:17,410 --> 00:11:19,420 So why reinvent the wheel right? 131 132 00:11:19,420 --> 00:11:21,070 Why not just customize it? 132 133 00:11:21,070 --> 00:11:22,530 But what if it's not enough? 133 134 00:11:22,540 --> 00:11:29,140 What if we wanted to create something that is really different? Well we can also build our very own widgets 134 135 00:11:29,380 --> 00:11:35,710 from the very basic Flutter components such as basic shapes like circles or squares. And then change it's 135 136 00:11:35,710 --> 00:11:41,680 elevation or change its background color and change how it behaves, completely define our own widgets 136 137 00:11:41,740 --> 00:11:43,100 and the way it should work. 137 138 00:11:43,210 --> 00:11:46,960 And we're going to be exploring exactly that in the next lesson. 138 139 00:11:47,170 --> 00:11:49,410 So all of that and more, I'll see you there. 15657

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.