我是飞翼开发的新手。我正在使用我的应用程序的下拉按钮。打开下拉菜单时,文本将在弹出对话框中被剪切。下面我附上了一个截图与编码。请指导我解决这个问题。
DropdownButtonHideUnderline(
child: new DropdownButton(
isExpanded: true,
value: dropDownValue,
isDense: true,
//icon: Icon(Icons.keyboard_arrow_down, color: Colors.white,),
onChanged: (String newValue) {
setState(() {
dropDownValue = newValue;
state.didChange(newValue);
});
},
items: dropDownList.map((String value) {
return new DropdownMenuItem(
value: value,
child: new SizedBox(
width: MediaQuery.of(context).size.width / 1.4,
child: new Text(value,
softWrap: true,
style: TextStyle(color: Colors.white, fontSize: 18.0),),)
);
}).toList(),
),
),
);
3条答案
按热度按时间1hdlvixo1#
按照其他人的建议复制
DropdownMenuItem
类是不够的,因为DropdownButton
要求items
的类型为List<DropdownMenuItem<T>>
。我创建了以下小部件,可以帮助解决您的问题:
它实际上扩展了
PopupMenuButton
,但我使它看起来与DropdownButton
相同。itemBuilder
需要返回List<PopupMenuEntry<T>>
,每个条目通常是一个PopupMenuItem
,您可以向其提供任何child
小部件。selectedValue
是当前选择的值,将在覆盖图中突出显示。如果为null,则显示带有placeholder
字符串的Text
小部件。如果不为空,则显示child
小部件。您应该能够通过修改这个类来禁用突出显示,要么调用
super()
,initialValue
为null,要么更好地向构造函数添加一个布尔值,以便从外部控制它。mum43rcc2#
DropdownMenuItem
的高度被硬编码为_kMenuItemHeight
:https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/dropdown.dart#L486
您唯一能做的就是复制整个文件并根据需要进行调整。
blpfk2vs3#
只需将
DropdownButton
的itemHeight
属性设置为null
,项目就具有动态高度。文档链接:https://api.flutter.dev/flutter/material/DropdownButton/itemHeight.html