[英]How to fix Flutter dropdown button overflow issue?
我創建了一個顫振表單,並使用顫振構建了一個下拉按鈕。 我正在將本地子數據丟失到下拉列表中。 我在下拉按鈕中的一些項目很長。 我使用 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...';
},
),
],
))));
盡管我已將該問題標記為可能重復,但另一個問題中未提及的部分解決方案是使用DropDownButton
的isExpanded
屬性。
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) { }
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.