【发布时间】:2023-03-13 08:53:01
【问题描述】:
【问题讨论】:
【问题讨论】:
有一个Widget 称为DropDownButton。有关更多信息,请查看该小部件的 docs。您可以通过将List<DropdownMenuItem<T>> 传递给菜单的items 参数来将项目添加到菜单中。
DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
);
【讨论】: