我们有一个包含20多个元素的列表,我们必须在下拉列表中显示这些元素。问题在于,当我们部署下拉列表时,列表覆盖了所有屏幕。我们希望将显示元素的数量减少到大约5或6,并能够向下滚动列表的其余部分。 我们还想知道是否有可能将dropDownMenuItems部署在dropDownButton下。
我们尝试做“ .toList()。sublist(0,5)”,但是这种方式不允许我们滚动。
Widget _dropdown() {
return new Container(
width: MediaQuery.of(context).size.width * 35 / 100,
height: MediaQuery.of(context).size.height * 6 / 100,
decoration: BoxDecoration(
backgroundBlendMode: BlendMode.darken,
),
child: Theme(
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: new DropdownButton(
hint: Text(
'HINT TEXT',
),
value: selected_item,
onChanged: (newValue) {
setState(
() {
selected_item = newValue;
},
);
},
isDense: false,
isExpanded: true,
items: data.map((location) {
return new DropdownMenuItem<String>(
child: new Container(
child: Align(
alignment: Alignment.centerLeft,
child: new Text(
location.toUpperCase(),
),
),
),
value: location,
);
}).toList(),
),
),
),
),
);
}
答案 0 :(得分:0)
查看此custom DropDown Button。这是正常的下拉按钮,可以为小部件提供高度。如果将height设置为5 * 48.0(即_menuItemHeight),则应该只能看到5个元素。