flutter dart 在下拉列表 DropdownMenuItem和DropdownButton 报错
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════The following assertion was thrown building StatefulBuilder(dirty, state: _StatefulBuilderState#87d0
·
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building StatefulBuilder(dirty, state: _StatefulBuilderState#87d0c):
There should be exactly one item with [DropdownButton]'s value: Hired Merchant.
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 827 pos 15: 'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem<T> item) {
return item.value == value;
}).length == 1'
flutter dart 在下拉列表 DropdownMenuItem和DropdownButton 报错 直接红屏 显示上面 信息 这是因为下拉列表中item每个value不能相同 会导致机器识别不了 所以列表集合需要进行 查重处理 清除重复
而这个问题只需要一行代码就能解决 dart太爽了
把原来的List进行 toSet后再toList处理就直接去重 原理是set集合内部会进行查重
更多推荐
已为社区贡献14条内容
所有评论(0)