我有以下DropdownButton小部件:
Center(
child: DropdownButton<dynamic>(
value: selectedTipoInterno,
items: dataTiposInt.map(
(list) {
return DropdownMenuItem(
child: Text(list['tipo_int']),
value: list['id'],
);
},
).toList(),
onChanged: (value) {
setState(() {});
},
),
)这里有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"}]我得到以下错误输出:
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'发布于 2022-01-22 23:20:03
我希望我能做一点评论,但还没有足够的声誉。
在您的代码中,datatiposInt的值是这样写的吗?或者它是生成的?如果是后者,那么查看代码也是有帮助的。
另外,我猜您的selectedTipoInterno不是字符串类型的,所以我想知道这是否会抛出下拉列表。
https://stackoverflow.com/questions/70817897
复制相似问题