Exception has occurred.
_AssertionError ('package:flutter/src/material/dropdown.dart': Failed assertion: line 882 pos 15: 'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem<T> item) {
return item.value == value;
}).length == 1': There should be exactly one item with [DropdownButton]'s value: 1.
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value)
我有这个错误,而我试图张贴1如果选择的下拉菜单是'全职',2如果选择的下拉菜单是'兼职和3如果选择的下拉菜单是'实习
DropdownButton(
hint: Text("Select Job type"),
value: currentValue,
isDense: true,
icon: const Icon(Icons.keyboard_arrow_down),
items: <String>[
if (currentValue == "1")
("Full-time")
else if (currentValue == "2")
("Part-time")
else
"Internship",
].map((String i) {
return DropdownMenuItem(
value: i,
child: Text(i),
);
}).toList(),
onChanged: onChangedCallback,
),
我的onChangedCallback如下所示
var currentValue =“1”;
Future<void> onChangedCallback(String? item) async {
if (item != null) {
currentValue = item;
final url = "my-api-link";
final body = {"job_type": item};
final response = await http.post(Uri.parse(url), body: body);
print(response.body);
}
}
2条答案
按热度按时间jc3wubiy1#
试试这个:
oug3syen2#
在下拉菜单中填充项目参数之前,必须设置“值”参数。
参考下面的例子,其中'dropdownValue'被初始化为'list.first',因为这个我得到了异常。