【发布时间】:2021-09-07 21:15:17
【问题描述】:
所以我有一个我在下面定义的预定义选项列表
final List<DropdownMenuItem> grades = <DropdownMenuItem>[
DropdownMenuItem(value: "Highschool", child: Text('Highschool')),
DropdownMenuItem(value: "Senior High", child: Text('Senior High')),
DropdownMenuItem(value: "College", child: Text('College'))];
而我要做的就是遍历列表,放到下拉菜单下
Form(
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
value: defState,
onChanged: (String? newValue) {
setState(() {
defState = newValue!;
});
},
items: grades.map((items) => return items),
hint: Text("Grade"),
),
)),
)
但它给了我这两个错误
The argument type 'Iterable<DropdownMenuItem<dynamic>>' can't be assigned to the parameter type 'List<DropdownMenuItem<String>>?'.
Unexpected text 'return'.
Try removing the text.
有没有办法迭代列表以便我可以立即返回?
【问题讨论】:
-
或者只是
items: grades -
都试过了还是一样的错误
标签: list flutter dart mobile widget