0

我遇到了以下问题:我希望用户使用下拉按钮选择一个月中的某一天。所以我的项目是数字 1 到 31。现在列表变得很长,下拉按钮非常大。是否有解决方案可以同时显示例如 5 个元素?

Widget buildDropdownMonthlyTurnus() {
return DropdownButton<int>(
    value: _selectedDay,
    icon: Icon(Icons.arrow_downward),
    iconSize: 24,
    elevation: 16,
    style: TextStyle(color: Colors.blue),
    underline: Container(
      height: 2,
      color: Colors.blue,
    ),
    onChanged: (int newValue) {
      setState(() {
        _selectedDay = newValue;
      });
    },
    items: Constants.daysOfMonth.map((int value) {
      return new DropdownMenuItem<int>(
        value: value,
        child: new Text(
          value.toString(),
          style: new TextStyle(color: Colors.black),
        ),
      );
    }).toList());

}

在链接中,您会看到我对大列表的问题。

在此处输入图像描述

4

1 回答 1

0

对于这个问题,您可以在容器内使用 listview 并显示根据显示的列表项管理其大小,您根本不需要使用下拉项。

于 2021-04-08T10:46:19.407 回答