我有一个问题:单击DropdownButton时,它会显示一长串可供选择的项目,但我不知道如何减少显示的项目数量。
我添加为列表和DropdownButton创建的代码
List _months = [
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
];
@override
void initState() {
super.initState();
txt = TextEditingController();
_dropDownMenuItems = getDropDownMenuItems();
}
List<DropdownMenuItem<String>> _dropDownMenuItems;
String _currentMonth;
List<DropdownMenuItem<String>> getDropDownMenuItems() {
List<DropdownMenuItem<String>> items = List();
for (String month in _months) {
items.add(DropdownMenuItem(
value: month,
child: Text(
month,
),
));
}
return items;
}
DropdownButton(style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
iconEnabledColor: Colors.white,
value: _currentMonth,
items: _dropDownMenuItems,
onChanged: changedDropDownItem)
有人可以帮助我吗?谢谢