All language subtitles for 14. [Dart] Maps

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

0 All right. 1

Let's talk quickly about Dart maps and how they work and how we can create them and what we can use them 2

for. When we're talking about Dart maps 3

it kind of refers to not like a map of the world, but more like how something can map onto something 4

else. 5

So for example if I type this last June longitude into Google maps, it will map onto a specific location. 6

And even better than that, you should think of maps as almost like a phone book 7

right? 8

Let's say that I have three friends. 9

I hope you have more friends than I do. 10

Amy, James and Tim and I keep their phone numbers in a book because I'm old school like that. 11

Now a phonebook is kind of like a very basic sort of map. 12

It's able to associate two pieces of data together. 13

So usually you would have a key, in this case it'd would be the names of my friends, 14

and then you would have some values and these would be the values that are associated with the keys. 15

This is how maps are. They're kind of like a collection type just like lists which we saw earlier. 16

But unlike lists, maps are unordered. So they don't go from zero to one to two because it doesn't make 17

sense to order your names in your phone book unless you're super OCD and you really want them to be 18

alphabetized and you would rewrite your phonebook every single time you had a friend that had a name 19

beginning with A. But essentially all that maps are is we have a key and we have a value and the key 20

will map onto a value and we can pull out the value if we know the key. In code, 21

what this would look like is something like this. 22

So they would be contained inside a set of curly braces. 23

We have a key 24

and then after a colon we have the value that's associated with that key. And all of these entries are 25

separated by a comma. 26

So this is how we would create it 27

and this is how we would use it. If we wanted to create a map, we can specify the data type as a map data 28

type, and then we can have a set of angle brackets and just like when we had lists where we put in the 29

data type all of the values that are in the list, 30

in this case we can specify the data type of the keys and the data type of the values so that when we 31

create our map or when we try to add values to our map our compiler can check to make sure that the key fits 32

the initial key type and the value fits the value type. 33

And if we want to use our map we simply refer to the name of the map, 34

use some square brackets and provide a key. And this will end up giving us the value that's associated 35

with that key. 36

So let's create a new map from scratch. 37

I'm going to start out by providing the data type which is going to be a map data type. And I could just 38

leave it at that and get Dart to figure out what are the data types of the entries in the map. 39

But if I wanted to help it along and also help other programmers who I'm working with to be able to 40

see at a glance what is contained inside this particular map, then I could add some angle brackets. And 41

inside, I could provide the data types of my key first which in my case is going to be a string, the names 42

of my friends. And then the value is going to be an integer, 43

the phone numbers of those people. 44

And so this is how that full data type looks like. I'm creating a collection of type map 45

and it has a key that will be string, and it'll have associated values which will be an integer. And 46

then I get to give it a name. 47

So let's call it I did a phonebook 48

right? 49

And it's gonna be set to equal a new map. 50

So I'm going to open out with some curly braces and inside here is where I will specify my keys and 51

values. 52

Now in this case my keys have to be a string. 53

So let's say that we create a key called 54

I don't know, 55

Kyle, and then we would add a colon to say that this is the end of the key. 56

And now I'm going to write the value that's gonna be associated with Kyle, so let's say that he's at 57

some random phone number. And then I can separate each of the entries in my collection with a comma. 58

So I'm going to paste in the ones from our previous keynote just for time sake. 59

And now if we cap off the end of our map with a semicolon, we can reformat our map to make it look pretty. 60

So here we have a map of strings and integers, 61

it's called phone book, 62

it's contained inside a set of curly braces and it's got four entries. 63

So now what I can do is I can start using my map. 64

So for example if I wanted to print out the value that is in my phonebook for maybe let's say Amy right? 65

Then I could write phonebook, add a set of square brackets denoting that I'm trying to pull something 66

out of a collection, and then I would provide the key which obviously has to match one of the keys in 67

my map. 68

So let's try and get Amy's phone number printed into the console. So let's hit run and we can see that 69

we get 123456789, which is the value that's associated with the key Amy. 70

Now if I tried to pull out a key that doesn't actually exist in the map, let's say try to get my own 71

number out of this phonebook, then all we'll get is null. When it tries to pull out of value for a key 72

that doesn't exist 73

you will get the value 74

null. 75

So it's easy to check against this if you wanted to see if a particular key existed. You could just see 76

if phone book at a particular key is equal to null, do this. 77

Else do that. 78

Now we can also use this particular syntax, 79

the square brackets, to add new values into our phonebook, 80

that doesn't yet exist. 81

So let's say I write phonebook and I'm going to add a value for my own name now. 82

So I'm going to add phonebook for the key 83

Angela is now going to be equal to, 84

let's add some random numbers. 85

And now if I tried to again print phonebook 86

for the key Angela, you can see that this now works and I no longer get null printed in here. So the cool 87

thing about maps is that it's unordered. 88

It doesn't really matter at which point your entries go in because you don't need to pull them out in 89

order, as in 0 is Kyle, 90

1 is Amy. And instead you can actually get the values out of the map using something that's quite easy 91

to read and easy to understand when you're looking at it at a glance. 92

This syntax is very expressive. 93

Now there's a number of methods that make it easy for you to use a map. 94

So for example you could write phonebook.length to see how many entries you currently have in the 95

phonebook. 96

So that's four plus this one which is five. 97

Or you could write phonebook.keys to print out all of the keys that's in the phone book. And it will 98

print out everything it's currently got. Or you can do the same for values as well and it'll print out 99

all the values it has. So we're going to be seeing maps a lot more in the coming lessons. 100

And it's just a convenient way of putting items into a collection not in any particular orde,r but searchable 101

by their keys.

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