All language subtitles for 21. Connecting Widgets & Managing Data State

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,490 --> 00:00:09,000 To receive our transactions in the transaction list file in the transaction list widget here, we can 2 00:00:09,000 --> 00:00:14,760 first of all add a new final property here which is a list of transactions, 3 00:00:14,760 --> 00:00:20,910 so this doesn't change, which I'll name transactions, of course you can use a different name here. 4 00:00:23,050 --> 00:00:26,130 So we have that final list of transactions and that should be set 5 00:00:26,130 --> 00:00:31,910 with the help of the constructor now because the constructor is how we can pass data from the parent 6 00:00:31,940 --> 00:00:38,630 widget into a child widget, so into this widget here. For that, I'll use the shortcut and expect to get 7 00:00:38,630 --> 00:00:43,010 the transactions as my first and only positional argument. 8 00:00:43,110 --> 00:00:48,780 So now incoming transactions are saved here and instead of _userTransactions, we again now use 9 00:00:48,780 --> 00:00:57,240 just transactions here, referring to this list. Now in user transactions where I do instantiate that transaction 10 00:00:57,240 --> 00:00:58,090 list widget, 11 00:00:58,260 --> 00:01:04,740 we now have to pass our list of transactions and that here simply is _userTransactions. 12 00:01:04,740 --> 00:01:09,930 So thus far, we just did a lot of reorganization without actually getting closer to the point where we 13 00:01:09,930 --> 00:01:11,480 can add a new transaction 14 00:01:11,550 --> 00:01:13,200 but this will change now. 15 00:01:13,360 --> 00:01:20,010 Now in the user transaction file where we manage our list of transactions, we can add a new method, a method 16 00:01:20,040 --> 00:01:24,510 that doesn't need to return anything and therefore will have a return tab of void and which I will 17 00:01:24,510 --> 00:01:27,560 then name add new transaction. 18 00:01:27,570 --> 00:01:33,000 The name is up to you, though it should start with an underscore to mark this as part or as private and 19 00:01:33,000 --> 00:01:37,210 as part of that private class here. In here, 20 00:01:37,240 --> 00:01:43,540 I expect to get two pieces of information, I expect to get my title which will be a string and I expect 21 00:01:43,540 --> 00:01:51,320 to get my amount which actually should not be a string but a double let's say. So here I get my title 22 00:01:51,320 --> 00:01:58,370 and my amount and I then want to create a new transaction here. So I'll create a new variable which 23 00:01:58,370 --> 00:02:06,470 I'll call newTx maybe, it's final because here I create it with the values that are passed into this 24 00:02:06,530 --> 00:02:06,970 method, 25 00:02:07,000 --> 00:02:12,580 so it is create based on values which I don't know at the point of time I'm writing the code, 26 00:02:12,650 --> 00:02:20,090 hence const can't be used here but I can use final because once that transaction has been created with 27 00:02:20,090 --> 00:02:22,370 these dynamic values, it will not change again. 28 00:02:22,970 --> 00:02:29,000 So here, I will create a new transaction by using the transaction constructor and for my title, I pass 29 00:02:29,000 --> 00:02:32,250 the title. Now to avoid confusion, 30 00:02:32,270 --> 00:02:39,350 I'll name this txTitle here, you don't have to rename it, you can use the same argument name here as 31 00:02:39,350 --> 00:02:42,540 you expect here but to avoid confusion on what's what, 32 00:02:42,620 --> 00:02:47,900 txTitle is what I pass as a value because I get it here as an input to this method and I pass this 33 00:02:47,990 --> 00:02:54,500 as a value for the named title argument on my transaction constructor. For the amount argument, I pass 34 00:02:54,500 --> 00:02:57,370 txAmount. Again 35 00:02:57,380 --> 00:03:03,450 you could have named txTitle just title and txAmount just amount, that would have been okay. 36 00:03:03,470 --> 00:03:09,250 Now we also need to pass an ID and a date. For the moment, we have no way of selecting the date, 37 00:03:09,260 --> 00:03:10,460 we have no date picker 38 00:03:10,460 --> 00:03:11,710 the user could use, 39 00:03:11,780 --> 00:03:18,070 so why don't we again use datetime now to use the current date? And now for the ID, 40 00:03:19,730 --> 00:03:27,210 I want to have a value which is kind of generated automatically and unique and therefore I'll also use 41 00:03:27,220 --> 00:03:27,500 datetime 42 00:03:27,510 --> 00:03:29,770 now to string here. 43 00:03:29,840 --> 00:03:31,220 It's not perfectly unique, 44 00:03:31,220 --> 00:03:35,410 theoretically we could add two transactions at the exact same timestamp 45 00:03:35,510 --> 00:03:37,640 but here for this app, it will do for now 46 00:03:38,030 --> 00:03:39,410 and it will be a string 47 00:03:39,500 --> 00:03:45,140 and it is generated automatically so we can treat this as a kind of unique ID for now. 48 00:03:45,320 --> 00:03:46,540 This is the new transaction 49 00:03:46,550 --> 00:03:50,750 and this new transaction should now be added to the user transactions list. 50 00:03:51,170 --> 00:03:57,410 For that, since I also want to update the user interface because build should run again to rebuild our 51 00:03:57,410 --> 00:04:04,660 transaction list and then also rebuild new transaction, that's the side effect, since I want to update 52 00:04:04,660 --> 00:04:05,010 that, 53 00:04:05,020 --> 00:04:12,580 I have to call set state now which I can call because we're inside of a state class, extending state, 54 00:04:12,700 --> 00:04:18,220 so we can call set state in here and inside of that function you pass to set state, 55 00:04:18,370 --> 00:04:26,650 I will use my user transactions which is that property up here and now, I want to add a new transaction. 56 00:04:26,650 --> 00:04:29,790 Now of course, that is marked as final 57 00:04:29,920 --> 00:04:36,340 but remember what I explained earlier when we talked about final and const? I mentioned that Dart stores 58 00:04:36,370 --> 00:04:43,420 objects in memory and only stores the pointer at these objects, the address in your variables. 59 00:04:43,600 --> 00:04:51,280 So _userTransactions holds a pointer at this list, the pointer, the address itself is final, 60 00:04:51,340 --> 00:04:58,110 we can't do user transactions equals something, that would not be allowed because then we would try to 61 00:04:58,110 --> 00:05:03,600 assign a new value to user transactions and user transactions is a final variable. 62 00:05:03,780 --> 00:05:09,510 What we can do however is we can interact with that list because that doesn't change the pointer, 63 00:05:09,510 --> 00:05:11,320 the object stays the same, 64 00:05:11,340 --> 00:05:18,090 we just manipulate the object and that can be done with the help of add. Add is a method we can call on 65 00:05:18,090 --> 00:05:24,390 a list to add a new element to that list, so that will change the existing list but it will not generate 66 00:05:24,390 --> 00:05:29,430 a new pointer or a new address and therefore we don't violate this being final, 67 00:05:29,490 --> 00:05:34,170 we just added the object that's stored in this final variable. 68 00:05:34,170 --> 00:05:39,510 So here, I add a value and that value of course is my new transaction. 69 00:05:39,510 --> 00:05:45,000 Now thanks to set state, that should be reflected on the user interface and a new transaction should 70 00:05:45,000 --> 00:05:48,950 be added to our list. To now see that all come together, 71 00:05:48,950 --> 00:05:51,870 let's go back to the main.dart file and there, 72 00:05:51,890 --> 00:06:01,010 let's now add our user transactions widget, on which we worked, below our chart container here and for that, 73 00:06:01,070 --> 00:06:08,220 as always, you need to add an import which should be ./widgets/user_transaction.dart, then that's 74 00:06:08,250 --> 00:06:10,470 added here below the container. 75 00:06:10,470 --> 00:06:16,710 Now last but not least, we have to make sure that when a user now presses this button, the add transaction 76 00:06:16,710 --> 00:06:23,220 but we don't just print the text of that transaction but that we actually trigger that add transaction, 77 00:06:23,220 --> 00:06:26,540 that add new transaction function in user transactions. 78 00:06:26,550 --> 00:06:28,780 Here's your chance to wire that up on your own, 79 00:06:28,860 --> 00:06:30,930 we'll of course do it together in the next lecture. 8806

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