如何修复 Flutter 下拉按钮溢出问题?
How to fix Flutter dropdown button overflow issue?
我创建了一个 Flutter 表单,并使用 flutter 构建了一个下拉按钮。我正在将本地子数据丢失到下拉列表中。我的下拉按钮中的某些项目很长。我使用 SafeArea 和 ListView,但右侧出现溢出。
其他问题中没有提到的部分解决方案,我在这里得到答案。
知道如何解决吗?
// TODO: BUILD RUN
return new Scaffold(
key: _scaffoldKey,
body: new SafeArea(
top: false,
bottom: false,
child: new Form(
key: _formKey,
child: new ListView(
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 32.0),
children: <Widget>[
//TODO: CURRENCY
new FormField<String>(
builder: (FormFieldState<String> state) {
return InputDecorator(
decoration: InputDecoration(
labelText: 'CHOOSE CURRENCY',
labelStyle: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: Colors.green.shade700),
errorText: state.hasError ? state.errorText : null,
),
isEmpty: _mySelectedCurrency == '',
child: new DropdownButtonHideUnderline(
child: new DropdownButton<String>(
style: TextStyle(
fontSize: 14.0,
color: Colors.black,
fontWeight: FontWeight.w500,
),
value: _mySelectedCurrency,
isDense: true,
onChanged: (String newValue) {
setState(() {
_mySelectedCurrency = newValue;
state.didChange(newValue);
});
},
items: _itemsName,
),
),
);
},
validator: (val) {
return val != '' ? null : 'Choose Currency...';
},
),
],
))));
虽然我已将问题标记为 ,但另一个问题中未提及的部分解决方案是将 isExpanded
属性 用于 DropDownButton
。
child: new DropdownButton<String>(
isExpanded: true,
...
在大多数情况下,除了扩展之外,将其设为椭圆形也很好。步骤 1 和 2。如果它不是椭圆形,它将换行到下一行,如果组件不支持多行它会截断文本。
DropdownButton(
isExpanded: true, //Step 1
items: [
new DropdownMenuItem(
child: Text("Long text that overflow the size.. wrapped or ellipsized",
overflow: TextOverflow.ellipsis), //Step 2
),
],
onChanged: (val) { }
)
我创建了一个 Flutter 表单,并使用 flutter 构建了一个下拉按钮。我正在将本地子数据丢失到下拉列表中。我的下拉按钮中的某些项目很长。我使用 SafeArea 和 ListView,但右侧出现溢出。
其他问题中没有提到的部分解决方案,我在这里得到答案。
知道如何解决吗?
// TODO: BUILD RUN
return new Scaffold(
key: _scaffoldKey,
body: new SafeArea(
top: false,
bottom: false,
child: new Form(
key: _formKey,
child: new ListView(
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 32.0),
children: <Widget>[
//TODO: CURRENCY
new FormField<String>(
builder: (FormFieldState<String> state) {
return InputDecorator(
decoration: InputDecoration(
labelText: 'CHOOSE CURRENCY',
labelStyle: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: Colors.green.shade700),
errorText: state.hasError ? state.errorText : null,
),
isEmpty: _mySelectedCurrency == '',
child: new DropdownButtonHideUnderline(
child: new DropdownButton<String>(
style: TextStyle(
fontSize: 14.0,
color: Colors.black,
fontWeight: FontWeight.w500,
),
value: _mySelectedCurrency,
isDense: true,
onChanged: (String newValue) {
setState(() {
_mySelectedCurrency = newValue;
state.didChange(newValue);
});
},
items: _itemsName,
),
),
);
},
validator: (val) {
return val != '' ? null : 'Choose Currency...';
},
),
],
))));
虽然我已将问题标记为 isExpanded
属性 用于 DropDownButton
。
child: new DropdownButton<String>(
isExpanded: true,
...
在大多数情况下,除了扩展之外,将其设为椭圆形也很好。步骤 1 和 2。如果它不是椭圆形,它将换行到下一行,如果组件不支持多行它会截断文本。
DropdownButton(
isExpanded: true, //Step 1
items: [
new DropdownMenuItem(
child: Text("Long text that overflow the size.. wrapped or ellipsized",
overflow: TextOverflow.ellipsis), //Step 2
),
],
onChanged: (val) { }
)