How can I get data from Map and put it in dropdown menu? I have an api working on websocket which returns me a Map of objects like {"1":"cat", "2":"dog","3":"bird"}, so I wanted to create a dropdown where users can choose the animal. As I know, the Map has key/value pair, so I need to use value in my case for drop-down menu. So my code now looks like that:
body: Futurebuilder<Map>(
future: apiservice.getAnimal(),
builder:(context, snapshot){
return: DropdownButton(
value: snaphot.data.first,
onChanged: (String newValue) {
setState(() {
snapshot.data.first = newValue;
});
},
items: snapshot.data.values.map((key, value) {
return DropdownMenuItem(
value: i,
child: Text(value));
}).toList(),
);})
But data doesn't display or it gives the error that string can't be the Map<dynamic, dynamic>. How can I solve it?