Flutter 如何在DropdownButtonFormField中居中显示提示文本?
我想在我的表单字段中居中显示提示文本。我怎样才能做到这一点 我尝试过使用Flutter 如何在DropdownButtonFormField中居中显示提示文本?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我想在我的表单字段中居中显示提示文本。我怎样才能做到这一点 我尝试过使用Align小部件,但不起作用 以下是我当前的代码: List<String> options = [ 'Main room', 'Side Room', 'Bathroom(lol)', 'Back Room', ]; DropdownButtonFormField<String>( decoration: InputDecoration(enabledBo
Align
小部件,但不起作用
以下是我当前的代码:
List<String> options = [
'Main room',
'Side Room',
'Bathroom(lol)',
'Back Room',
];
DropdownButtonFormField<String>(
decoration: InputDecoration(enabledBorder: InputBorder.none),
items: options.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Align(
alignment: Alignment.center,
child: Text(value, style: TextStyle(fontSize: 20))),
);
}).toList(),
isDense: true,
isExpanded: false,
hint: Align(
alignment: Alignment.center,
child: Text(options[0], style: TextStyle(fontSize: 20))),
onChanged: (_) {},
)
列表选项=[
“主房间”,
“侧屋”,
“浴室(lol)”,
“后面的房间”,
];
下拉按钮窗体字段(
装饰:Input装饰(enabledBorder:InputBorder.none),
项:options.map((字符串值){
返回下拉菜单项(
价值:价值,
子对象:对齐(
对齐:对齐.center,
子项:文本(值,样式:TextStyle(fontSize:20)),
);
}).toList(),
是的,
isExpanded:错,
提示:对齐(
对齐:对齐.center,
子项:文本(选项[0],样式:TextStyle(fontSize:20)),
一旦改变:({},
)
因此,我希望文本居中,但结果如下:
您必须更改
扩展名:true
最终代码:
DropdownButtonFormField<String>(
decoration: InputDecoration(enabledBorder: InputBorder.none),
items: options.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Align(
alignment: Alignment.center,
child: Text(value, style: TextStyle(fontSize: 20))),
);
}).toList(),
isDense: true,
isExpanded: true,
hint: Align(
alignment: Alignment.center,
child: Text(options[0], style: TextStyle(fontSize: 20))),
onChanged: (_) {},
)
DropdownButtonFormField(
装饰:Input装饰(enabledBorder:InputBorder.none),
项:options.map((字符串值){
返回下拉菜单项(
价值:价值,
子对象:对齐(
对齐:对齐.center,
子项:文本(值,样式:TextStyle(fontSize:20)),
);
}).toList(),
是的,
是的,
提示:对齐(
对齐:对齐.center,
子项:文本(选项[0],样式:TextStyle(fontSize:20)),
一旦改变:({},
)
如果答案有帮助,请告诉我!这就解决了!谢谢