Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,480 --> 00:00:08,510
With that, back to our application here and before we continue working on the user interface where we
2
00:00:08,510 --> 00:00:11,680
of course still have lots of work left to do,
3
00:00:11,690 --> 00:00:14,840
let me actually first work on the data we're outputting.
4
00:00:15,020 --> 00:00:20,600
With that, I mean this price here which doesn't really look like a price,
5
00:00:20,600 --> 00:00:23,350
there is no dollar sign in front of it for example
6
00:00:23,420 --> 00:00:29,900
and I also mean the date, I want to change the formatting or the content of these two pieces
7
00:00:29,900 --> 00:00:35,600
of data which were outputting here. Now for that, let's start with the price, with the amount we're
8
00:00:35,600 --> 00:00:36,500
outputting
9
00:00:36,580 --> 00:00:43,400
and there I have a special syntax or I want to show you a special syntax you can use in Dart, not just
10
00:00:43,400 --> 00:00:49,220
in Flutter, to output values in a text or as a text.
11
00:00:49,220 --> 00:00:54,620
Right now I'm outputting the amount here with the help of to string and that is the perfectly fine way
12
00:00:54,620 --> 00:00:55,560
of doing that
13
00:00:55,700 --> 00:00:57,140
and this is actually all we need
14
00:00:57,140 --> 00:01:02,180
if all we want to output is the amount value here as a string.
15
00:01:02,180 --> 00:01:08,580
But if I want to add a dollar sign in front of that, I actually can also concatenate this string together
16
00:01:08,600 --> 00:01:09,750
with another string,
17
00:01:09,980 --> 00:01:14,270
I can add dollars sign here and then add a plus to combine these two strings.
18
00:01:14,270 --> 00:01:16,050
And normally this would work, here
19
00:01:16,050 --> 00:01:19,150
however, Dart doesn't like this for some reason.
20
00:01:19,150 --> 00:01:26,960
Now let's first of all try an alternative which will work if I add simply a colon for amount or whatever,
21
00:01:26,960 --> 00:01:28,630
so a colon and then a whitespace
22
00:01:28,640 --> 00:01:34,660
and then I have the plus and then the amount to string and I save this and here we see a colon empty amount.
23
00:01:34,740 --> 00:01:38,550
Now that's nice but I don't want to show a colon but a dollar sign.
24
00:01:38,600 --> 00:01:43,540
So what's special about the dollar sign? For this, let's first of all understand how we could shorten
25
00:01:43,550 --> 00:01:48,040
this here. Concatenating strings like this with a plus is perfectly fine
26
00:01:48,050 --> 00:01:55,160
but Dart actually has a more concise and shorter syntax for that. Instead of combining strings with a
27
00:01:55,160 --> 00:02:00,950
plus, which gets especially cumbersome if you have very long strings with a lot of different segments,
28
00:02:01,520 --> 00:02:07,900
you can use a special syntax where you use the dollar sign, which actually has a special meaning in Dart
29
00:02:07,900 --> 00:02:15,590
strings, which is why we had this error before and after the dollar sign, you can reference a variable
30
00:02:15,590 --> 00:02:18,110
or a property name to output that here.
31
00:02:18,110 --> 00:02:26,570
So here we could type tx and now it would try to inject the value of tx here in that place.
32
00:02:26,570 --> 00:02:31,090
So if we now save that and we go back, we see some strange error here on the right,
33
00:02:31,160 --> 00:02:34,460
that simply is shown because we're exceeding the boundaries here,
34
00:02:34,460 --> 00:02:36,080
let's ignore it for now.
35
00:02:36,080 --> 00:02:42,050
More interesting is that we see instance of transactions, so indeed we are outputting our transaction
36
00:02:42,050 --> 00:02:42,420
here.
37
00:02:42,500 --> 00:02:48,740
An instance of transaction is simply what you see when you call tx to string
38
00:02:48,890 --> 00:02:52,160
and that's called for you here automatically.
39
00:02:52,160 --> 00:02:57,230
Now the more interesting thing is that of course here I don't want I'll put my entire transaction but
40
00:02:57,350 --> 00:03:00,560
my amount and therefore we can also use .amount here,
41
00:03:00,770 --> 00:03:08,270
however if you are trying to inject or to interpolate as it's called more, than just the variable itself,
42
00:03:08,270 --> 00:03:13,910
so if you use more than just a variable name, like here where I also use the dot notation, then you have
43
00:03:13,910 --> 00:03:19,160
to wrap that expression which you're trying to interpolate into curly braces.
44
00:03:19,160 --> 00:03:26,150
So then you have dollar sign and then curly braces and between the curly braces, you have your expression
45
00:03:26,390 --> 00:03:32,210
which should resolve to a string or to something where to string can be called on, which will then be
46
00:03:32,210 --> 00:03:33,610
called automatically by Dart
47
00:03:34,220 --> 00:03:38,020
so that this string gets now added in this place here.
48
00:03:38,030 --> 00:03:42,980
So now I've actually remove txAmount to string here at the end and I just have this syntax,
49
00:03:43,100 --> 00:03:49,490
if we now go back, we indeed see our amount here again but now using a feature called string interpolation
50
00:03:49,690 --> 00:03:55,340
and that's a very handy feature since this is obviously shorter than combining multiple pieces of text
51
00:03:55,340 --> 00:03:56,630
together with a plus.
52
00:03:56,780 --> 00:04:03,080
We also don't have to call to string here because Dart does this for us when we use this string interpolation
53
00:04:03,080 --> 00:04:04,550
syntax.
54
00:04:04,560 --> 00:04:05,380
Now that's all nice
55
00:04:05,390 --> 00:04:09,950
but of course I wanted to add a dollar sign here and not a colon and a whitespace.
56
00:04:09,980 --> 00:04:13,470
However the dollar sign as you can tell is a reserved character,
57
00:04:13,580 --> 00:04:16,070
the dollar assigned to Dart means that
58
00:04:16,070 --> 00:04:18,800
you plan on interpolating some value
59
00:04:18,800 --> 00:04:22,350
but what if you want the dollar sign as a character?
60
00:04:22,370 --> 00:04:27,600
Well you can do something which we already did earlier when we wanted to output a quote.
61
00:04:27,800 --> 00:04:32,370
Then you might remember we added a backslash in front of it to escape it,
62
00:04:32,390 --> 00:04:37,940
so to tell Dart that this should not be treated as a language feature, to close a string but instead
63
00:04:37,970 --> 00:04:43,520
as a normal character and you can do exactly the same with a dollar sign. If you don't want the special
64
00:04:43,520 --> 00:04:49,160
meaning it has to Dart but you want the character dollar sign, then you add a backslash in front
65
00:04:49,160 --> 00:04:52,940
of it and you simply add the dollar sign after the backslash.
66
00:04:52,940 --> 00:04:57,780
So now this dollar sign after the backslash here will just be output as text,
67
00:04:57,800 --> 00:05:03,580
this dollar sign here however, since there is no backslash directly in front of it, will be treated as
68
00:05:03,580 --> 00:05:06,000
the beginning of a string interpolation
69
00:05:06,020 --> 00:05:10,990
and with that if we save this, we have the dollar sign in front of the amount. That was a lot of talking just
70
00:05:10,990 --> 00:05:12,230
to add a dollar sign
71
00:05:12,250 --> 00:05:16,840
but the core takeaway of course is not just that you can escape it but that it has a special meaning
72
00:05:17,050 --> 00:05:19,510
and that you can use it in string interpolation.
7864
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.