gpt4 book ai didi

flutter - Flutter:如何最小化DropdownButton的宽度

转载 作者:行者123 更新时间:2023-12-03 13:29:19 25 4
gpt4 key购买 nike

Flutter中的DropdownButton根据其具有的最大DropdownMenuItem设置其宽度。如果选择了一个小项目,则该项目和箭头之间会留有很多空白。如何使按钮缩放为刚好适合所选项目的宽度?

我尝试使用Expanded和一些Flexible的东西,但我仍然无法更改它的宽度。

DropdownButton(
value: null,
hint: Text("Small text"),
items: ..., //Text widgets that have more text and are larger than the hint
)

我试图摆脱 hint和箭头之间加下划线的空格:
enter image description here

最佳答案

这有效:

new Container(
padding: const EdgeInsets.fromLTRB(10.0, 5, 10, 0),
child: new Container(
padding: const EdgeInsets.fromLTRB(10, 5, 5, 5),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(5.0),
bottomLeft: const Radius.circular(5.0),
bottomRight: const Radius.circular(5.0),
topRight: const Radius.circular(5.0))),
child: new Center(
child: new Column(children: [
new DropdownButton(
underline: Text(''),
icon: Icon(Icons.keyboard_arrow_down),
hint: new Text('Small text'),
style: TextStyle(
color: Colors.white30,
),
isExpanded: true,
value: _selectedLocation,
onChanged: (String newValue) {
setState(() {
_selectedLocation = newValue;
});
},
items: _locations.map((String location) {
return new DropdownMenuItem<String>(
value: location,
child: new Text(
location,
style: TextStyle(
color: myColour, fontWeight: FontWeight.bold),
),
);
}).toList(),
),
])),
))

关于flutter - Flutter:如何最小化DropdownButton的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56490858/

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