Flutter: Filter list as per some condition

后端 未结 3 1299
感动是毒
感动是毒 2020-12-13 07:56

I\'m having list of Movies. That contains all Animated & non Animated Movies. To identify whether its Animated or not there is one flag called as isAnimated

相关标签:
3条回答
  • 2020-12-13 08:32

    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);

    0 讨论(0)
  • 2020-12-13 08:36

    You can use toList() method to get your desire output like following

    toList() Collects all elements of this stream in a List.

    To fix the above issue:

    Add a toList() (This code creates a List<dynamic>)

    _AnimatedMovies = AllMovies.where((i) => i.isAnimated).toList();
    

    instead of

    _AnimatedMovies = AllMovies.where((i) => i.isAnimated);
    

    0 讨论(0)
  • 2020-12-13 08:48

    toList() is missing to materializer the result

    _AnimatedMovies = AllMovies.where((i) => i.isAnimated).toList();
    
    0 讨论(0)
提交回复
热议问题