嗨,我有一个下拉按钮,其提示和所选值文本过长会被截断:
它应该显示“部门代码/部门编号”
代码:
DropdownButton<String> dropdownList(BuildContext context) {
return new DropdownButton<String>(
hint: new Text(
"Department Code / Department Number",
),
value: selectedDept,
isDense: true,
onChanged: (String newValue) {
//...
},
items: _item.map((Dept map) {
return new DropdownMenuItem<String>(
value: map.code,
child:
new Text(map.code, style: new TextStyle(color: Colors.black)),
);
}).toList(),
isExpanded: true,
);
}
Widget build(BuildContext context) {
return Scaffold(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(
20, 20, 10, 20),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 1.0,
style: BorderStyle.solid,
color: Colors.grey[400]),
borderRadius:
BorderRadius.all(
Radius.circular(
15.0)),
),
),
child:
DropdownButtonHideUnderline(
child: dropdownList(
context)),
)
]
)
)
}
任何想法如何固定显示器?
从文档Text widget documentation中,您可以试用overflow
softWrap
maxLines
属性。
只需添加填充以在内部内容之间留出空间。
return DropdownMenuItem<String>(
value: value,
child: Padding(
padding: EdgeInsets.all(4),
child: Text(map.code, style: new TextStyle(color: Colors.black)),
),
);
在Container()中,添加BoxConstraints并指定minHeight和maxHeight
constraints: new BoxConstraints(
minHeight: 50.0,
maxHeight: 70.0,
)