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.
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(),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With