List 如何在Flatter中将地图列表显示到下拉菜单项中
我是新来的。 我想显示列表变量中的DropdownMenuItem。 查看我的代码List 如何在Flatter中将地图列表显示到下拉菜单项中,list,flutter,dart,List,Flutter,Dart,我是新来的。 我想显示列表变量中的DropdownMenuItem。 查看我的代码 // my list variable List listUserType = [ {'name': 'Individual', 'value': 'individual'}, {'name': 'Company', 'value': 'company'} ]; // items property in DropdownMenuItem return DropdownBut
// 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());
//我的列表变量
列表listUserType=[
{'name':'Individual','value':'Individual'},
{'name':'Company','value':'Company'}
];
//DropdownMenuItem中的items属性
返回DropdownButtonFormField(
装饰:输入装饰(
前缀:图标(图标.设置),
hintText:“组织类型”,
是的,
fillColor:Colors.white,
errorStyle:TextStyle(颜色:Colors.yellow),
),
条目:listUserType.map((映射){
返回下拉菜单项(
子:文本(映射['name']),
值:映射['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>>>>'
I/颤振(22528):══╡ WIDGETS库捕获到异常╞═══════════════════════════════════════════════════════════
I/flatter(22528):在构建RegisterPage(dirty,state:RegisterPageState#5b83a)时抛出了以下断言:
I/颤振(22528):类型“列表”不是类型的子类型
I/颤振(22528):“列表”
我不知道是什么导致了这个错误 尝试删除
将
DropdownButtonFormField
更改为DropdownButtonFormField
,并将字符串
类型参数添加到返回DropdownMenuItem
是否可以为DropDown发布完整的代码已编辑代码下拉列表用于显示一个项目,如果可以为显示键
或值
,则我会尽力帮助,否则我不知道该怎么办
return DropdownButtonFormField(
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());