Reputation:
I'm having issues simply printing what's inside a DropdownButton
by looping the results of an API request that fetches the following:
[{id: 1, nome: foo}, ...]
This is the code for it.
return _response.data.map<Client>((i) => Client.fromJson(i)).toList();
Which oddly, when printing the variable that stores the above call is [Instance of 'Client', ...]
Then, in the view, I attempt to at least print each item:
DropdownButton<Client>(
onChanged: (client) => print(client),
items: _controller.clients
.map(
(i) => print(i),
)
.toList(),
But type 'List<void>' is not a subtype of type 'List<DropdownMenuItem<Client>>'
. I am lost already.
Upvotes: 0
Views: 134
Reputation: 51750
Where you are printing i
, you instead need to be returning a DropDownMenuItem
(with a child)
For example:
items: _controller.clients.map((e) => DropDownMenuItem(value: e, child: Text(e.nome))).toList(),
Upvotes: 2