我无法将 DropdownButton 中的所选项目与中心对齐。
我已经尝试过在 DropdownMenuItem 下的 child: Center(),它能够对齐这些项目,但是在我选择了其中一个项目后,所选项目立即与左侧对齐。我还想将所选项目与中心对齐。
有谁知道如何实现它?
提前致谢。
_dropdownValues:
final List<String> _dropdownValues = [
"One",
"Two12345",
"Three123456789",
"Four",
];
String _selectedValue;
Run Code Online (Sandbox Code Playgroud)
在小部件构建下:
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
child: Text('Name:',),
),
Container(
child: Center(
child: DropdownButton(
hint: Text('Select ...'),
items: _dropdownValues.map((value) => DropdownMenuItem(
child: Center( child: Text(value), ),
value: value,
)).toList(),
onChanged: (String value) {
setState(() {
this._selectedValue = value;
});
},
isExpanded: false,
value: _selectedValue,
),
),
),
],
),
),
Run Code Online (Sandbox Code Playgroud)