Flutter下拉按钮显示文字截断
Dropdown button display text cut off Flutter
您好,我有一个下拉按钮,当它的提示和选定值文本太长时会被截断:
应该显示"Department Code / Department Number"
代码:
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)),
)
]
)
)
}
知道如何修复显示吗?
只需在您的内部内容之间添加填充即可 space。
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,
)
如果您不想增加下拉列表的大小,请将内容填充更改为适合您的内容。
DropdownButtonFormField(
itemHeight: 50,
decoration: InputDecoration(
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 10),
.
.
.
contentPadding 通常有一个默认值,它会剪切您的文本。
要访问输入修饰,您需要使用 DropdownButtonFromField
您好,我有一个下拉按钮,当它的提示和选定值文本太长时会被截断:
应该显示"Department Code / Department Number"
代码:
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)),
)
]
)
)
}
知道如何修复显示吗?
只需在您的内部内容之间添加填充即可 space。
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,
)
如果您不想增加下拉列表的大小,请将内容填充更改为适合您的内容。
DropdownButtonFormField(
itemHeight: 50,
decoration: InputDecoration(
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 10),
.
.
.
contentPadding 通常有一个默认值,它会剪切您的文本。 要访问输入修饰,您需要使用 DropdownButtonFromField