【发布时间】:2023-01-17 17:27:02
【问题描述】:
我是 flutter 的初学者,我正在尝试放置 4 个 dropdownbutton ,当我更改第二个的值时,出现错误:
[DropdownButton] 的值应该只有一项:Dollars。 检测到具有相同值的零个或两个或多个 [DropdownMenuItem] '包:dropdown_button2/dropdown_button2.dart': 包:dropdown_button2/dropdown_button2.dart:1 断言失败:第 1128 行第 11 行:'items == null || 项目.isEmpty || 价值==空|| items.where((DropdownMenuItem 项目) { 返回 item.value == 值; }).长度== 1'
第一个工作:
String lang = 'English'; var items = [ 'English', 'Polish', ]; DropdownButtonHideUnderline( child: DropdownButton2( items: items .map( (item) => DropdownMenuItem<String>( value: item, child: Text( item, style: const TextStyle( fontSize: 14, ), ), ), ) .toList(), value: lang, onChanged: (String? newValue) { setState(() { lang = newValue!; }); }, ), ),第二个不是
String currency = 'Dollars'; var curriencies = [ 'Dollar', 'Euro', 'PLN', 'Funts', ]; DropdownButtonHideUnderline( child: DropdownButtonFormField2( items: curriencies .map( (currency) => DropdownMenuItem<String>( value: currency, child: Text( currency, style: const TextStyle( fontSize: 14, ), ), ), ) .toList(), value: currency, onChanged: (String? newValue) { setState(() { currency = newValue!; }); },我更改了值,但它仍然相同
【问题讨论】:
-
什么是价值:货币?
-
抱歉,我的错是它切断了“String currency = 'Dollars';”这一行,我现在已经编辑了
-
将 Dollars 更改为 Dollars,因为此数组中不存在 Dollars - [ 'Dollar', 'Euro', 'PLN', 'Funts', ]
标签: flutter