Home > front end >  A value of type 'Iterable<Type>' can't be returned from the method 'genere
A value of type 'Iterable<Type>' can't be returned from the method 'genere

Time:03-02

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

CodePudding user response:

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

CodePudding user response:

The suggestion provided by Richard(in comments) is the solution for your problem and I think you need to visit this question to have better understanding.

  • Related