All language subtitles for 33. Adding Images to the App

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,300 --> 00:00:03,620 Custom fonts are great, 2 00:00:03,620 --> 00:00:05,590 what about custom images? 3 00:00:05,630 --> 00:00:11,510 Let's say if we have no transactions, I want to show some image that indicates that we have no content, 4 00:00:11,510 --> 00:00:14,360 that we're waiting for new content. For that, 5 00:00:14,360 --> 00:00:19,750 first of all let's make sure that we can have no content by going to the main.dart file and there, 6 00:00:19,940 --> 00:00:24,380 let's remove or comment out these two default transactions. 7 00:00:24,380 --> 00:00:31,380 Now with that if we reload this, we'll have a pretty empty space over here, so there's nothing there and 8 00:00:31,380 --> 00:00:32,720 there, I want to show an image now. 9 00:00:32,720 --> 00:00:36,370 For that, we first of all need an image. 10 00:00:36,370 --> 00:00:42,100 Now you can also add images that are stored somewhere in the web but of course you can also include 11 00:00:42,130 --> 00:00:42,970 local images 12 00:00:42,970 --> 00:00:48,820 and here I want to use a local image. For that in our assets folder, next to the fonts folder, 13 00:00:48,840 --> 00:00:50,060 I'll add an images folder. 14 00:00:50,070 --> 00:00:57,050 The name is up to you, just as it was with the fonts folder, you just should have some strategy or idea 15 00:00:57,080 --> 00:00:58,360 for storing images 16 00:00:58,970 --> 00:01:01,440 and I'll copy an image into that folder. 17 00:01:01,520 --> 00:01:05,450 Here is a file, you find it attached to this lecture, waiting.png, 18 00:01:05,560 --> 00:01:07,850 it's a couple of Zs over here. 19 00:01:07,850 --> 00:01:10,220 So we have that image 20 00:01:10,220 --> 00:01:15,140 and now I want to include that image here instead of my list of transactions, 21 00:01:15,140 --> 00:01:21,980 so instead of this widget if we have no transactions. I'll actually write the logic for that inside 22 00:01:21,980 --> 00:01:23,250 of the transaction list 23 00:01:23,270 --> 00:01:30,600 so that our main widget tree here doesn't get too huge, too large. So in transaction list here, 24 00:01:30,750 --> 00:01:40,010 I only want to render this ListView builder widget with all its list items if we have no transactions, 25 00:01:40,150 --> 00:01:44,910 otherwise I want to render some text where I say no transactions added yet 26 00:01:44,950 --> 00:01:54,430 and that image. Since we have a either or decision here, we in the end need a ternary expression. So let's 27 00:01:54,430 --> 00:01:57,860 add one, we receive our transactions here 28 00:01:57,870 --> 00:02:03,470 so I want to check if transactions is empty, 29 00:02:03,580 --> 00:02:12,340 in that case here, I want to render my text and that image, otherwise after the colon, the list of transactions. 30 00:02:12,340 --> 00:02:16,720 So here I need a column because I want to have the text and above and below the text, I want to have 31 00:02:16,720 --> 00:02:29,970 the image. So let's add first of all the text and there, I'll say no transactions added yet, with 32 00:02:29,970 --> 00:02:32,420 lowercase t and that can be a title 33 00:02:32,430 --> 00:02:40,920 so why don't we give it a style of theme of context.textTheme.title which is what you learned 34 00:02:40,920 --> 00:02:43,940 about in the last lectures and below that, 35 00:02:43,940 --> 00:02:47,240 let's add an image and for this, we can use the image widget 36 00:02:47,240 --> 00:02:51,500 and there we have a couple of constructors for the different sources 37 00:02:51,500 --> 00:02:58,430 the image could be coming from. There is asset, if it's provided as an asset in our project, file would 38 00:02:58,430 --> 00:03:04,360 be good for images that are in files that you obtained in a different way 39 00:03:04,370 --> 00:03:08,360 but by streaming in some image, something like this. Network is great 40 00:03:08,360 --> 00:03:10,240 if you have a URL for the image, 41 00:03:10,250 --> 00:03:13,740 so if it's not stored as part of your project but it's a web image 42 00:03:13,740 --> 00:03:15,410 but here of course it's part of our project 43 00:03:15,410 --> 00:03:18,800 so we need asset. And then you need the path to the image here 44 00:03:18,800 --> 00:03:24,350 and that's assets/images/waiting.png. 45 00:03:24,440 --> 00:03:26,990 Now just like fonts, adding an image here isn't enough, 46 00:03:26,990 --> 00:03:31,170 you also need to include it in your pubspec.yaml file. There, 47 00:03:31,370 --> 00:03:38,960 you should already have a section that shows you how to add it. You add an assets key and then a path to 48 00:03:38,960 --> 00:03:42,940 all the assets, the none font assets you want to use in your app. 49 00:03:43,010 --> 00:03:46,780 In this case, that's assets/images 50 00:03:46,880 --> 00:03:51,200 and by the way, it's important that you have assets here just because this key is named like this does 51 00:03:51,200 --> 00:03:55,650 not mean that it goes into your assets folder automatically, 52 00:03:55,820 --> 00:04:00,350 it's a pure coincidence that this folder is named assets and this key is named assets. 53 00:04:00,350 --> 00:04:07,430 So here you need to add the full path which is assets/images/waiting.png. Typical image 54 00:04:07,430 --> 00:04:16,240 formats like jpg, png and and gif are supported. So with that, we added the image and now just as before, you 55 00:04:16,510 --> 00:04:23,880 need to quit that and then fully restart your application after you added this new file here. 56 00:04:23,920 --> 00:04:26,260 So now this file will be included in your bundle 57 00:04:26,290 --> 00:04:31,860 and thanks to image assets here in the transaction list widget, it should also be displayed, 58 00:04:31,870 --> 00:04:33,590 so the image should also be displayed then. 59 00:04:33,640 --> 00:04:37,360 So let's wait for this build process to finish 60 00:04:37,880 --> 00:04:39,240 and here we are. 61 00:04:39,260 --> 00:04:48,290 So we see the image but as it seems, it's too big. We get this warning that some content is overflowing 62 00:04:48,290 --> 00:04:53,210 its boundaries and that's the case here because our transaction list actually only gets a container 63 00:04:53,210 --> 00:04:57,570 with height 300 and that image simply is bigger than that. 64 00:04:57,780 --> 00:05:03,590 Of course we could provide a smaller image but maybe on bigger screens, on bigger devices, we want a bigger 65 00:05:03,590 --> 00:05:04,000 image 66 00:05:04,010 --> 00:05:08,170 because maybe at some point in the future, we calculate this height dynamically. 67 00:05:08,210 --> 00:05:12,960 We're not doing this right now but we'll later learn about tools that allow us to do that. 68 00:05:13,010 --> 00:05:17,450 So it would be great if we could squeeze the image into that container and tell Flutter that it should 69 00:05:17,450 --> 00:05:23,710 size the image appropriately and you can do that. On the image here, 70 00:05:23,900 --> 00:05:31,820 you can add a fit key and set that to a BoxFit value. BoxFit is an enum and gives you a couple of options 71 00:05:32,180 --> 00:05:37,790 and cover is a great option that respects the boundaries of the surrounding container and fits the image 72 00:05:37,790 --> 00:05:38,830 into there. 73 00:05:38,840 --> 00:05:43,520 The problem with that just is that we have no boundaries here. 74 00:05:43,640 --> 00:05:44,540 We have the container 75 00:05:44,540 --> 00:05:47,900 but the direct parent of the image is not the container but the column 76 00:05:48,020 --> 00:05:51,620 and you learned that columns take as much height as they can get. 77 00:05:51,650 --> 00:05:57,660 So the image is not able to infer the size into which I should squeeze the image from the column, 78 00:05:57,770 --> 00:06:01,790 it would need access to the container but that's outside of the column. 79 00:06:02,270 --> 00:06:03,740 Solution is simple, 80 00:06:04,160 --> 00:06:11,090 we can wrap our image here into another widget, for example into a container 81 00:06:11,090 --> 00:06:18,320 and now that image is wrapped in there, we can give this container a height of let's say 200 and once 82 00:06:18,320 --> 00:06:24,770 we do that, now the image fits in there because now BoxFit here is able to take the height of its direct 83 00:06:24,800 --> 00:06:29,100 parent and squeeze the image in there and this gives us this look. 84 00:06:29,240 --> 00:06:35,330 Now what I would like to have is some spacing between our title here and the image and there is 85 00:06:35,330 --> 00:06:40,700 another widget which makes this super simple. Below the text, above our image container here, 86 00:06:40,970 --> 00:06:43,490 you can add a sized box. 87 00:06:43,700 --> 00:06:45,320 We haven't seen that widget before, 88 00:06:45,320 --> 00:06:47,720 sized box does what the name suggests, 89 00:06:47,780 --> 00:06:54,470 it allows us to add a box with a specific size. You can add a child in here, so you can add content 90 00:06:54,470 --> 00:06:59,780 in here and actually we could replace this container here with a sized box because all we do is assign 91 00:06:59,780 --> 00:07:00,200 a height 92 00:07:00,620 --> 00:07:03,460 and that's exactly something you can do in sized boxes too, 93 00:07:03,470 --> 00:07:05,630 you can set widths and heights. 94 00:07:05,690 --> 00:07:11,510 The cool thing is you can also not define a child here and therefore sized boxes are also a common 95 00:07:11,510 --> 00:07:17,420 way of using them as separators, as to provide some spacing between elements because this will be an 96 00:07:17,450 --> 00:07:24,650 empty box which we don't see on the screen but which still occupies its space, it still occupies 10 pixels 97 00:07:24,650 --> 00:07:29,540 of vertical space here and therefore now we have some spacing, a little bit more spacing between the 98 00:07:29,540 --> 00:07:31,220 image and the title and 99 00:07:31,220 --> 00:07:36,560 of course you can ramp up that spacing to increase that distance. 100 00:07:36,740 --> 00:07:37,280 So this is good 101 00:07:37,280 --> 00:07:38,900 now we have that waiting picture 102 00:07:38,930 --> 00:07:43,480 and as soon as we do add a transaction here like new shoes, 103 00:07:47,620 --> 00:07:52,220 that actually disappears and we see our transactions then, as it should be the case. 104 00:07:52,330 --> 00:07:55,060 So now we also saw how we can add our own images. 10944

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