Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,370 --> 00:00:03,510
Were you successful?
2
00:00:03,510 --> 00:00:09,260
Let's wire it up together and for this, let's go to the new transaction file and here for onPressed,
3
00:00:09,870 --> 00:00:13,920
I now want to call that add new transaction method.
4
00:00:13,920 --> 00:00:19,100
The problem just is this method is a private method in a private class in a different file,
5
00:00:19,140 --> 00:00:23,460
so there is no way how we can access it directly.
6
00:00:23,460 --> 00:00:25,060
Well actually there is a way.
7
00:00:25,170 --> 00:00:30,490
Remember that this in the end also just creates a pointer at this function here in the end,
8
00:00:30,750 --> 00:00:34,460
we can pass that pointer down to a new transaction
9
00:00:34,470 --> 00:00:43,290
So here to new transaction, I can pass add new transaction, so I can pass basically that function pointer
10
00:00:43,290 --> 00:00:46,120
here by the name without adding parentheses,
11
00:00:46,260 --> 00:00:51,690
if we would add parentheses, we would immediately execute this when Dart parses this line, without parentheses
12
00:00:51,690 --> 00:00:53,770
we just pass down the pointer.
13
00:00:53,850 --> 00:00:57,030
Now in new transaction, we need to accept that pointer.
14
00:00:57,030 --> 00:01:07,540
So here I'll add a new final property which is of type function, which I'll name addTx or whatever
15
00:01:07,540 --> 00:01:08,790
you want to name it
16
00:01:08,950 --> 00:01:13,930
and that should be set with the help of the constructor of new transaction because we're passing something
17
00:01:13,930 --> 00:01:19,750
to the constructor here in user transactions and therefore we should provide such a constructor here
18
00:01:19,870 --> 00:01:20,770
in new transaction.
19
00:01:21,250 --> 00:01:29,450
So add new transaction and bind whatever you get to addTx, so not whatever you get,
20
00:01:29,470 --> 00:01:34,150
of course we know that what we get will be a pointer at a function and we bind that pointer into the
21
00:01:34,270 --> 00:01:41,200
addTx variable here. Since addTx holds a pointer at a function, we can now execute it like a function here. In
22
00:01:41,200 --> 00:01:44,170
onPressed, we can execute addTx
23
00:01:44,170 --> 00:01:50,650
and now here we need to pass the value for our title and also the value for our amount.
24
00:01:51,490 --> 00:01:52,570
So here I'll pass
25
00:01:52,570 --> 00:01:59,260
titleController.text and also amountController.text.
26
00:01:59,260 --> 00:02:04,290
Now here's one tiny issue, text here always returns us a string
27
00:02:04,480 --> 00:02:12,030
but actually in our ad new transaction method here, we expect the amount to be a double.
28
00:02:12,100 --> 00:02:23,080
Now to convert that string to a double, you can go to new transaction and actually use double.parse
29
00:02:23,100 --> 00:02:30,300
and this will take a string and convert it to a double. Now important, if you entered a text that can't
30
00:02:30,300 --> 00:02:31,150
be converted,
31
00:02:31,230 --> 00:02:36,240
something like hello, then this will throw an error and your app will break.
32
00:02:36,240 --> 00:02:41,250
So in reality, you might want to also provide some logic that would handle such an error
33
00:02:41,250 --> 00:02:45,810
but since we haven't learned that yet and it's not that important right now, we'll handle errors later,
34
00:02:46,170 --> 00:02:46,620
for now
35
00:02:46,620 --> 00:02:49,550
be aware that you have to enter a valid number here, otherwise
36
00:02:49,560 --> 00:02:54,640
this will break. Now with that, everything is wired up.
37
00:02:54,640 --> 00:02:57,610
If we save this and we go back, that's looking good
38
00:02:57,610 --> 00:03:02,820
and now let's give this a try, enter test here and here as I said enter number, also important,
39
00:03:02,830 --> 00:03:09,850
that number needs to use a dot as a decimal place and now hit add transaction and you see it gets added
40
00:03:09,850 --> 00:03:11,710
here, which is of course pretty sweet.
41
00:03:12,940 --> 00:03:17,570
And of course we can add as many transactions here as we want,
42
00:03:17,770 --> 00:03:27,160
we can press this button over and over again, at some point however, we'll face a problem. If I enter more
43
00:03:27,160 --> 00:03:33,930
and more here, you see now we have that warning which we saw before already, this yellow black thing
44
00:03:33,930 --> 00:03:34,600
here,
45
00:03:34,800 --> 00:03:38,410
we now already see that even without the keyboard opened.
46
00:03:38,430 --> 00:03:40,790
So we should finally tackle what the issue here is
47
00:03:41,070 --> 00:03:43,860
and to give you a hint, it's related to another problem,
48
00:03:44,010 --> 00:03:45,820
we can't scroll this list,
49
00:03:45,840 --> 00:03:49,940
there is no way we can see the new transaction we added at the bottom.
50
00:03:50,270 --> 00:03:55,150
And that's not a bug, that's a default behavior which we can easily fix and we will fix it
51
00:03:55,170 --> 00:03:55,920
in the next lecture.
5311
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.