Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The argument type 'List<Iterable<DropdownMenuItem<int>>>' can't be assigned to the parameter type 'List<DropdownMenuItem<dynamic>>'

Tags:

flutter

In flutter I'm using TMDB API and getting genre names from there and want to display them on my DropdownButton but I got this error.

The argument type List < Iterable< DropdownMenuItem< int>>> can't be assigned to the parameter type 'List< DropdownMenuItem< dynamic>>

{
  "genres": [
    {
      "id": 28,
      "name": "Action"
    },
    {
      "id": 12,
      "name": "Adventure"
    },
    {
      "id": 16,
      "name": "Animation"
    }, .......]
}

this is the json.

return DropdownButton(
              items: [ snapGenre.data.genres.map((map) => DropdownMenuItem(child: Text(map.name),value: map.id,))]
                      );
                    }

this part is what I have tried.

Briefly what I want to do is, I want to return/create a dropDownMenuItem according how many genre name I get from the API. Which part I miss can you help me please.

like image 866
Emre SERBEST Avatar asked May 17 '19 23:05

Emre SERBEST


1 Answers

You are declaring a List by using [], and then mapping your data inside it, so you ended up with a Iterable inside a List. Instead, you must remove the [] and convert the Iterable to a List at the end:

return DropdownButton(
  items: snapGenre.data.genres.map((map) => DropdownMenuItem(
      child: Text(map.name),
      value: map.id,
    ),
  ).toList(),
);
like image 184
Hugo Passos Avatar answered Sep 26 '22 14:09

Hugo Passos