════════ 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集合内部会进行查重

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐