【发布时间】:2022-06-15 00:41:16
【问题描述】:
我在颤振中做了一个下拉菜单,它采用 Map
Map<String, int> grades = {
"AA": 5,
"BB": 4,
};
int val=5;
@override
Widget build(BuildContext context) {
return Scaffold(
body: DropdownButton<int>(
value: grades["AA"],
onChanged: (newVal){
setState((){
if(newVal!=null){ val=newVal;}
});
},
items: grades
.map((key, value) {
return MapEntry(
key,
DropdownMenuItem<int>(
value: value,
child: Text(key),
));
})
.values
.toList(),
));
【问题讨论】:
标签: flutter