【发布时间】:2019-11-07 05:05:27
【问题描述】:
我是 Flutter 的新手。 我想从我的列表变量中显示 DropdownMenuItem。 查看我的代码。
// my list variable
List listUserType = [
{'name': 'Individual', 'value': 'individual'},
{'name': 'Company', 'value': 'company'}
];
// items property in DropdownMenuItem
return DropdownButtonFormField<List<Map>>(
decoration: InputDecoration(
prefixIcon: Icon(Icons.settings),
hintText: 'Organisation Type',
filled: true,
fillColor: Colors.white,
errorStyle: TextStyle(color: Colors.yellow),
),
items: listUserType.map((map) {
return DropdownMenuItem(
child: Text(map['name']),
value: map['value'],
);
}).toList());
这是我得到的结果
I/flutter (22528): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (22528): The following assertion was thrown building RegisterPage(dirty, state: RegisterPageState#5b83a):
I/flutter (22528): type 'List<DropdownMenuItem<dynamic>>' is not a subtype of type
I/flutter (22528): 'List<DropdownMenuItem<List<Map<dynamic, dynamic>>>>'
我不知道是什么导致了错误。
【问题讨论】:
-
你能发布整个下拉代码
-
已编辑代码
-
DropDown 是为显示一项而设计的,如果可以显示
key或value,那么我会尽力提供帮助,否则我不知道该怎么办