gpt4 book ai didi

android - 有没有办法在 flutter 中为 DropdownButton 添加标签?

转载 作者:行者123 更新时间:2023-11-28 23:24:36 25 4
gpt4 key购买 nike

我正在尝试获得这种设计: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
[标签]

PS.: 我知道这不是一个正确的标签,因为它只是一个文本,如果有人能帮助我,那就太好了,在此先感谢。

最佳答案

如果我得到了您想要的正确结果,您将需要使用 Row (了解更多 here )来执行此操作,如下例所示,使用您的代码:

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(),
),
],
),
],
),
),
),
);

产生这个:

enter image description here

关于android - 有没有办法在 flutter 中为 DropdownButton 添加标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59035051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com