All language subtitles for 38. Creating Bars for our Chart

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: 1 00:00:02,440 --> 00:00:10,990 To get the grouped and summed up transactions on the screen, here in the chart.dart file, in the row where 2 00:00:10,990 --> 00:00:14,530 I output my bars or where I plan on outputting my bars, 3 00:00:14,530 --> 00:00:23,280 the goal now is to generate the children here for that row based on the grouped transaction values because 4 00:00:23,280 --> 00:00:29,100 that will be exactly seven items, since we generate seven items and we need these seven bars with all 5 00:00:29,100 --> 00:00:36,920 the information about the transactions for that day and so on. Hence down here, we can refer to grouped 6 00:00:36,920 --> 00:00:41,580 transaction values which is a list and map this into a list of widgets 7 00:00:41,600 --> 00:00:44,650 and as always, on map, you need to call to list in the end. 8 00:00:45,250 --> 00:00:49,060 Now here we have a function that executes on every item in that grouped 9 00:00:49,060 --> 00:00:55,900 transaction values list and that will receive the data or whatever you want to name it, that name is 10 00:00:55,900 --> 00:00:57,910 up to you for every element here. 11 00:00:58,900 --> 00:01:05,060 In there, we need to return a widget and we have no widget for that bar yet, we haven't created a widget 12 00:01:05,060 --> 00:01:07,540 that could be a bar in our chart. 13 00:01:07,640 --> 00:01:15,230 So for the moment, we can return some text here, so start and simply output data day here, which 14 00:01:15,230 --> 00:01:19,880 should be the shortcut for the weekday, plus a colon, 15 00:01:23,090 --> 00:01:32,960 plus data amount to string. 16 00:01:32,970 --> 00:01:39,280 Now of course as you learned, concatenating data like this is not really necessary, shortcut is that you have 17 00:01:39,280 --> 00:01:40,040 a string here, 18 00:01:40,060 --> 00:01:44,670 then you use dollar sign and then here, data day. 19 00:01:44,770 --> 00:01:51,840 However since it's more than just a single variable, you need to wrap that in curly braces and then we 20 00:01:51,840 --> 00:01:52,410 have a colon, 21 00:01:52,410 --> 00:01:58,080 this is now normal text and after that, we have again another string interpolation here where we access 22 00:01:58,080 --> 00:02:06,880 data amount and this will automatically be converted to a string then. If we save this, I get an error 23 00:02:06,880 --> 00:02:07,110 here, 24 00:02:07,120 --> 00:02:11,460 let's ignore it for now, it's just some overflow here because we're entering too much data. 25 00:02:11,500 --> 00:02:17,050 The important thing is that theoretically, it works though, super ugly but we see our weekday and then 26 00:02:17,080 --> 00:02:25,890 we also see our value. A small correction from my side, the weekday here is not yet a single digit, a 27 00:02:25,890 --> 00:02:28,620 single character. To turn it into a single character 28 00:02:28,620 --> 00:02:36,870 however, we can go here, to the place where we generate that formatted weekday and use the substring method, 29 00:02:36,990 --> 00:02:43,050 a default method you can use on any string in Dart, start at the first character which has the index 30 00:02:43,050 --> 00:02:47,650 of 0 and end after the first character, so before the second character 31 00:02:47,880 --> 00:02:51,870 and if you do that, now indeed you have TWT and so on. 32 00:02:52,440 --> 00:02:59,260 So it's a tiny fix but of course, the more important fix is that we render real bar charts here, real bars 33 00:02:59,280 --> 00:03:01,430 and not ugly text like this. 34 00:03:02,240 --> 00:03:07,460 So let's build the bars for our chart and therefore, I'll add a new file in the widgets folder, 35 00:03:07,550 --> 00:03:13,430 chart_bar.dart, that will simply hold the bars for my chart, 36 00:03:13,430 --> 00:03:18,200 it'll be a stateless widget because we don't need to change any data in a single bar. 37 00:03:18,260 --> 00:03:18,710 I'll name it 38 00:03:18,710 --> 00:03:24,920 chart_bar, you can of course name your widgets whatever you prefer and in there as always, we import the 39 00:03:24,920 --> 00:03:31,050 material.dart file, so that we unlock stateless widget and so on. Now in the chart bar, 40 00:03:31,050 --> 00:03:34,320 I expect some information, 41 00:03:34,320 --> 00:03:40,360 I of course want to have my label, so it detects the weekday. 42 00:03:40,360 --> 00:03:48,170 I also expect a double, which is my spending and there, 43 00:03:48,190 --> 00:03:56,650 I want to have the spending amount but I also and that's new, need a double which is my spending percentage 44 00:03:57,550 --> 00:03:58,600 of total 45 00:03:58,660 --> 00:04:00,990 if you want to name it like this. You could use a shorter name 46 00:04:01,000 --> 00:04:03,810 but I want to be really clear what this is. 47 00:04:04,030 --> 00:04:11,470 I need that, so that I know inside of that bar how I should colour the background because only a percentage 48 00:04:11,470 --> 00:04:13,780 of the bar should have the background colour, 49 00:04:13,780 --> 00:04:15,010 right? 50 00:04:15,010 --> 00:04:17,520 So these are the three pieces of information I need 51 00:04:17,730 --> 00:04:22,410 and here on my chart bar constructor, you could use named arguments, 52 00:04:22,500 --> 00:04:25,760 I will go for positional arguments and I'll get the label, 53 00:04:25,770 --> 00:04:33,650 the spending amount and the spending percentage of total. With that information, we can now work on the 54 00:04:33,650 --> 00:04:40,430 bar and that will be a column here because we have three items on top of each other or above each other, 55 00:04:41,400 --> 00:04:49,320 so let's add children here and the topmost item is, let's say the amount we spent on that day. So therefore 56 00:04:49,320 --> 00:04:54,990 here, that can be some text and the text I want to have in here should have a dollar sign and we need 57 00:04:54,990 --> 00:04:56,030 to escape that 58 00:04:56,040 --> 00:05:03,040 as you learned, so \$ and then a string interpolation with ${} 59 00:05:03,060 --> 00:05:13,090 where I use my spending amount but there I want to call toString as fixed to remove all 60 00:05:13,090 --> 00:05:18,580 decimal places by setting them to zero so that I have no decimal places here and I only show the 61 00:05:18,580 --> 00:05:27,510 rounded integer value so to say. So that's the topmost element, the text with the dollar signs. 62 00:05:27,740 --> 00:05:35,830 Then let's say we have a sized box to add some spacing, maybe 4 pixels and thereafter, a container, that's 63 00:05:35,840 --> 00:05:47,100 our main bar. This container might have a height of let's say 60 pixels and a width of maybe 10 and then 64 00:05:47,100 --> 00:05:55,050 the child should be a background that is filled to different amounts, 65 00:05:55,080 --> 00:06:01,710 we can fill that background fractionally so to say. Let's take care about the child in a second, 66 00:06:01,710 --> 00:06:05,810 for now let's add null here. After the container, 67 00:06:05,860 --> 00:06:12,940 I'll have another sized box here with let's say a height of 4 to add some spacing and below 68 00:06:12,940 --> 00:06:18,710 that, a text with my label, which holds the weekday. So now back to that container, 69 00:06:18,710 --> 00:06:22,940 how can we give this a background that's partially filled? For that 70 00:06:22,940 --> 00:06:27,790 let's use a new widget which I mentioned earlier on a slide but which we haven't used yet and 71 00:06:27,810 --> 00:06:33,950 that's the stack widget. The stack widget allows you to place elements on top of each other and with 72 00:06:33,950 --> 00:06:37,130 top, I mean in like a three dimensional space, 73 00:06:37,130 --> 00:06:42,300 so not on top of each other like a column but really overlapping each other. 74 00:06:42,350 --> 00:06:48,410 It also takes a children argument which takes a list of widgets and now the first widget you add here 75 00:06:48,410 --> 00:06:51,690 will be the bottommost widget. 76 00:06:51,720 --> 00:06:58,830 This should be a container with a decoration which is a box decoration object 77 00:07:01,350 --> 00:07:05,390 where I want to assign a border, let's say with border 78 00:07:05,410 --> 00:07:11,600 all in all directions of a gray color 79 00:07:11,600 --> 00:07:16,560 and here I'm not using the theme because this is really the only widget where I want this and the width 80 00:07:16,620 --> 00:07:20,720 of one pixel, 81 00:07:20,760 --> 00:07:24,640 I should also target my color here with colors gray. 82 00:07:25,090 --> 00:07:30,310 Besides that, the decoration for this container should be that I have a background color, which maybe 83 00:07:30,310 --> 00:07:32,200 is a light gray color. 84 00:07:32,320 --> 00:07:40,360 I'll also select this manually here and I'll not use gray from colors because that's too dark, instead 85 00:07:40,360 --> 00:07:44,700 here I'll use color and then that has a constructor from RGBO 86 00:07:44,710 --> 00:07:53,490 and that means it's allowing us to mix a color with red, green, blue and opacity values and here if 87 00:07:53,490 --> 00:08:01,230 you pass 220, 220, 220 and then 1, you should get a light gray color. 88 00:08:01,230 --> 00:08:05,280 So this is basically RGBA values being used, 89 00:08:05,280 --> 00:08:10,860 each value here can be between 0 and 255 and you can simply play around with that or use some color 90 00:08:10,860 --> 00:08:16,710 mixers on the Internet to generate your favorite color in our RGBA code. 91 00:08:16,710 --> 00:08:21,190 Last but not least, I want a border radius for some rounded corners 92 00:08:21,540 --> 00:08:27,750 and here we need a border radius geometry, we create that however with the border radius class and there, 93 00:08:27,750 --> 00:08:34,590 you can use the circular constructor to give that a border radius of let's say 20 pixels. 94 00:08:34,590 --> 00:08:35,590 You can play around with that, 95 00:08:35,610 --> 00:08:37,620 what fits your or what suits your needs, 96 00:08:37,620 --> 00:08:41,320 maybe let's use 10. With that, we have the overall container, 97 00:08:41,340 --> 00:08:43,110 that will be the main container 98 00:08:43,140 --> 00:08:50,100 and now I want to overlay, hence the stack, another container which is smaller, which has less height 99 00:08:50,160 --> 00:08:53,100 than 60 and which has a different background color 100 00:08:53,100 --> 00:08:57,740 so that we have the effect of that container here being partially filled. 101 00:08:58,110 --> 00:09:06,000 So therefore inside of the stack, above of that container because the elements here are from at the bottom 102 00:09:06,000 --> 00:09:08,500 to at the top ordered, 103 00:09:08,640 --> 00:09:15,450 so on top of that container, I'll add another container where I could manually set height differently 104 00:09:15,690 --> 00:09:21,020 or I use a special widget Flutter has, the fractionally sized box and 105 00:09:21,040 --> 00:09:26,850 this allows me to create a box that is sized as a fraction of another value. 106 00:09:26,850 --> 00:09:32,310 There you need to add a height factor and that height factor should be a value between 0 and 1 where 107 00:09:32,310 --> 00:09:35,850 one is 100% of the surrounding container, 108 00:09:35,850 --> 00:09:38,220 so in this case, this is the surrounding container, 109 00:09:38,220 --> 00:09:44,910 so one would give us a height of 60, zero would be zero and my percentage is of course my spending 110 00:09:44,910 --> 00:09:46,530 percentage of total here, 111 00:09:46,560 --> 00:09:49,290 I expect this to be a value between 0 and 1, 112 00:09:49,350 --> 00:09:55,990 so I pass this here as a value to height factor. Now since I can't set a decoration on the fractionally 113 00:09:55,990 --> 00:10:04,240 sized box but I can set a child, I'll add a container as a child here and that container now will have 114 00:10:04,270 --> 00:10:06,050 the background color I want. 115 00:10:06,070 --> 00:10:15,050 So I'll give it a declaration here, which is a box decoration, where I set the color, by the way you could set the 116 00:10:15,050 --> 00:10:21,050 color directly on the container too with the color argument but I want to use the decoration because 117 00:10:21,050 --> 00:10:27,970 I want to set more than just the color. So I'll set the color here and the color should be based on the theme 118 00:10:28,360 --> 00:10:34,870 so let's select it from our context and there, our primary color maybe, of course it's up to you which 119 00:10:34,870 --> 00:10:41,500 color you want to use and then set the same border radius as for the other border so that the two containers 120 00:10:41,530 --> 00:10:48,890 which are placed on top of each other are matching up regarding their borders and their edges and with 121 00:10:48,890 --> 00:10:51,530 that, we should have a bar that works. 122 00:10:51,530 --> 00:10:56,630 Let's now try it and let's make sure we pass in a value for spending percentage of total. 13596

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