可以Dropdown Button
:
return DropdownButton<String>(
items: <String>['Foo', 'Bar'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {},
);
与TextFormField
中的装饰用户类似:
TextFormField(
controller: _titleController,
decoration: InputDecoration(labelText: 'Input'),
validator: (String value) {
if (value != null && value.isEmpty) {
return 'Please enter some text';
}
},
style: Theme.of(context).textTheme.title,
),
当在上面的TextFormField中写入内容时,将显示单词Input
。像这样:
答案 0 :(得分:5)
用DropdownButtonFormField替换DropdownButton:
https://api.flutter.dev/flutter/material/DropdownButtonFormField-class.html
答案 1 :(得分:1)
将DropdownButton更改为DropdownButtonFormField并添加此装饰...。
decoration: InputDecoration(
filled: true,
fillColor: Hexcolor('#ecedec'),
labelText: 'Occupation',
border: new CustomBorderTextFieldSkin().getSkin(),
),