我正在尝试获得这种设计:1
[标签]:[下拉列表]
[标签]:[文本字段]
[标签]:[下拉列表]
我已经可以使用以下代码实现下拉菜单:
List<String> _locations = ['Cita', 'Junta', 'Proyecto', 'Examen', 'Otro']; // Option 2
String _selectedLocation; // Option 2
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Crear Evento'),
),
body: Center(
child: Container(
width: double.infinity,
height: 400,
padding: EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.center,
child: Column(
children: <Widget>[
new Text('Categoría'),
DropdownButton(
hint: Text('Categoría'), // Not necessary for Option 1
value: _selectedLocation,
onChanged: (newValue) {
setState(() {
_selectedLocation = newValue;
});
},
items: _locations.map((location) {
return DropdownMenuItem(
child: new Text(location),
value: location,
);
}).toList(),
),
],
),
),
),
);
但是,此输出不是我想要的方式,因为输出的格式为:2
[label]
PS .:我知道这不是一个标签,因为它只是一个文本,如果有人可以帮助我,那就太好了,谢谢。
如果我得到你想要什么权利,你需要使用一个行(阅读更多这里)要做到这一点,像下面的例子中,使用您的代码:
List<String> _locations = ['Cita', 'Junta', 'Proyecto', 'Examen', 'Otro']; // Option 2
String _selectedLocation; // Option 2
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Crear Evento'),
),
body: Center(
child: Container(
width: double.infinity,
height: 400,
padding: EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.center,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Categoría'),
Container(width: 8),
DropdownButton(
hint: Text('Categoría'), // Not necessary for Option 1
value: _selectedLocation,
onChanged: (newValue) {
setState(() {
_selectedLocation = newValue;
});
},
items: _locations.map((location) {
return DropdownMenuItem(
child: new Text(location),
value: location,
);
}).toList(),
),
],
),
],
),
),
),
);
产生这个:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句