可以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
。像这样:
用DropdownButtonFormField替换DropdownButton:
https://api.flutter.dev/flutter/material/DropdownButtonFormField-class.html