'A value of type 'Iterable<Type>' can't be returned from the method 'genereMovies' because it has a return type of 'List<Type>'
I want to separate list of movies based on their geneType
List<Movie> genereMovies(String gene) {
return movie.where((mov) => mov.geneType.contains(gene));
}
I have this getter that will find and return Object Movie which contains that gene
my object of movie looks like this
Movie(
id: 'm3',
title: 'Golmaal 2',
description: 'Best comedy movie by actor Ajay devgan',
rating: '4.0/5',
imageUrl:
'https://pixabay.com/get/g2367e312e5b444252dd1639ba9f27edfa04e269538d22d4a5f2e843639b0f535f61d3350bd66de32d1024443ed6ee872a11db93c9ddc14035a7e73a82a4e359ab8344f145d4097cf1be4f9ee642acaf7_1920.jpg',
geneType: ['comedy', 'action']),
geneType takes a list of Strings
Solution 1:[1]
The method where returns an Iterable. That's why you get the error, since you want to return a List but you actually have an Iterable. The class Iterable has the method toList() which creates a List.
List<Movie> genereMovies(String gene) {
return movie.where((mov) => mov.geneType.contains(gene)).toList();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | quoci |
