I have the following DropdownButton widget:
Center(
child: DropdownButton<dynamic>(
value: selectedTipoInterno,
items: dataTiposInt.map(
(list) {
return DropdownMenuItem(
child: Text(list['tipo_int']),
value: list['id'],
);
},
).toList(),
onChanged: (value) {
setState(() {});
},
),
)
And here you have the value for dataTiposInt:
[{"id":"1","tipo_int":"Administrador"},{"id":"2","tipo_int":"Editor"},{"id":"3","tipo_int":"Supervisor"},{"id":"4","tipo_int":"Analista"},{"id":"5","tipo_int":"Colaborador"}]
I am getting the following error output:
There should be exactly one item with [DropdownButton]'s value: Administrador.
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 894 pos 15: 'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem<T> item) {
return item.value == value;
}).length == 1'
>Solution :
I wish I could just do a little comment but don’t have enough reputation yet.
Is the value for datatiposInt written like that in your code? Or is it generated? If the latter, it might be helpful to see that code as well.
Also, I’m guessing that your selectedTipoInterno is not of type String, so I’m wondering if that throws off the dropdown in general