I'm having a list of movies. That contains all animated and non-animated movies. To identify whether it's Animated or not there is one flag called isAnimated
.
I want to show only Animated movies. How can I do that?
I'm having a list of movies. That contains all animated and non-animated movies. To identify whether it's Animated or not there is one flag called isAnimated
.
I want to show only Animated movies. How can I do that?
toList()
is missing to materializer the result
_AnimatedMovies = AllMovies.where((i) => i.isAnimated).toList();
List
add .toList()
–
Kalagher CompanyModel company = companies.where((c) => c.id == companyId).toList().first;
–
Hunsinger AllMovies.whereNotNull().where((i) => i.isAnimated).toList();
(not tested) –
Kalagher The Solution is here
Just try with this Function getCategoryList(),
Here the condition will be catogory_id == '1' from the list
List<dynamic> getCategoryList(List<dynamic> inputlist) {
List outputList = inputlist.where((o) => o['category_id'] == '1').toList();
return outputList;
}
You can use this for specific condition
List<String> strings = ['one', 'two', 'three', 'four', 'five'];
List<String> filteredStrings = strings.where((item) {
return item.length == 3;
});
where function on a List returns Iterable, you have to convert it to List using the function List.from(Iterable).
So in the above scenario, you should use the following code snippet.
Iterable _AnimatedMoviesIterable = AllMovies.where((i) => i.isAnimated);
_AnimatedMovies = List.from(_AnimatedMoviesIterable);
Edited:
As per Günter Zöchbauer solution, we can use a single line instead of multiple. So the code is
_AnimatedMovies = AllMovies.where((i) => i.isAnimated).toList();
toList()
method which is much easier to read IMHO. –
Kalagher © 2022 - 2024 — McMap. All rights reserved.