【发布时间】:2022-11-30 17:26:45
【问题描述】:
标签: flutter
标签: flutter
你可以通过使用DropdownButton widget来实现
这是使用它的代码示例:
@override
Widget build(BuildContext context) {
return DropdownButton<int>(
value: dropdownValue,
icon: const Icon(Icons.arrow_downward),
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (int? value) {
// This is called when the user selects an item.
setState(() {
dropdownValue = value!;
});
},
items: list.map<DropdownMenuItem<int>>((int value) {
return DropdownMenuItem<int>(
value: value,
child: Text("$value"),
);
}).toList(),
);
}
但是,我建议您使用 DatePicker 查看 documentation here,因为使用此小部件处理 flutter 中的日期会更容易。
【讨论】: