Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we took care of our shuffle function by relying upon some functionality that was
implemented in the standard library.
We're not going to move on to our next function, which is cards with suits.
Let's take a look at a diagram that's going to give you a better idea of the purpose of this function.
So I want you to imagine for a second that maybe we have this deck of cards shown at the top.
So ace of diamonds, two, three, and then ace of spades and two of spades.
If we call the cards with method on the deck class in passing a string of spades, then I would expect
to receive a list back to me with the ace of spades and the two of spades.
So essentially go through the deck and find all the cards with a particular suit.
Now, one thing I want to mention here is that we do not want to modify the original deck of cards,
so we're not trying to pull cards out of here.
I just want to get a list telling me all the cards with a particular suit that still exist inside the
deck.
OK, so let's go back over to Arpad Pad and we're going to start our implementation.
So back over here, I'll find my deck class, I'm going to add a new method to this class down at the
very bottom of the class itself.
And I'm going to call this cards with suit.
Now, as we just saw in that diagram two seconds ago, right over here, we clearly have to pass in
a string that indicates what suit we're trying to find.
So I'm going to make sure that I marked this method as requiring one argument that we will refer to
as simply suit.
So now, if you want to call the cards with suit method, you have to pass in some suit arguments.
One thing I want to mention here is that if you click on a suit and then look down at the type on the
bottom right hand side, it says dynamic suit.
The word dynamic here means that Dart is not able to figure out what type of variable suit is supposed
to be.
So this is a good example of where Dart's going to try to figure out what's going on with your code,
but it's not quite able to any time.
Dart does not have enough information to figure out what your code is trying to do.
I recommend annotating your values with a type.
We've already done this a couple of times inside of our project already.
You'll notice that, say, on the card class right here.
We specifically marked this suit as being type string and that gave Dart enough information to figure
out what type the suit property was supposed to be.
But in this case, we don't have enough information, and so I'm going to specifically mark this argument
as simple as requiring to be of type string.
So I want to make sure that if you ever call this cards with such argument, you pass in a single argument
that is a string.
So to do so.
All right.
Out string and then suit.
So now if I click on it again, you'll notice that it says string suit.
So we've now given darte enough information to figure out what type of variable suit is right here.
OK, so now that we are inside of our cards with suit method and we have the appropriate type of argument,
we can now write some logic to go into our list of cards and find every card with a given suit.
Now, you might be thinking that we're going to have to put together a for loop or something crazy like
that and iterate over all the cards within our deck.
But rather than doing that, we're going to, again, rely upon the standard library, particularly
some functionality that we get with every list for free.
So I'm going to, again, pull up the list documentation.
Remember, you can get here by going to API, darling Doug, and then you'll look for the dart core
module right here.
And then you can find the list section on the right hand side.
So once I'm back here, I'm going to scroll down towards the very bottom of the file.
So all the way down here, right above the operators section, I'll find a method called where?
So the we're method right here is going to return a new lazy iterable, let's don't worry about what
a lazy iterable is just yet.
It's essentially kind of something like a list.
But more importantly, it says that it's going to return an iterable with all the elements that satisfy
some given test.
So we're going to make use of this where method right here to automatically iterate through all the
items within our carts list and only return the items that satisfy some test that you and I are going
to write.
So let's take a pause right here.
We're going to come back the next section and we're going to start our implementation of this where
method.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.