【发布时间】:2021-11-02 21:55:45
【问题描述】:
我想要一个下拉按钮,其宽度基于菜单文本长度。下拉箭头在文本之间没有任何额外的间距。 像这样:
目前,我得到了这个:
我的下拉按钮箭头是根据最长的文本定位的。
我的代码:
Widget dropdownList(){
return Container(
child: DropdownButton<Location>(
value: _selectedValue,
icon: const Icon(Icons.expand_more),
iconSize: 30,
underline: SizedBox(),
onChanged: (Location? newValue) {
setState(() {
_selectedValue = newValue!;
});
},
style: const TextStyle(color: Colors.blue),
selectedItemBuilder: (BuildContext context) {
return locationList.map((Location value) {
return Container(
child: Text(
value.name,
style: const TextStyle(color: Colors.black,fontSize: 30,
fontWeight: FontWeight.w300),
),
);
}).toList();
},
items: locationList.map<DropdownMenuItem<Location>>((Location value) {
return DropdownMenuItem<Location>(
value: value,
child: Text(value.name, style: TextStyle(color: Colors.black,fontSize: 15,
fontWeight: FontWeight.w300)),
);
}).toList(),
),
);
}
【问题讨论】:
-
我不是 Flutter 开发者,但在 css display:inline-block 中,文本可以解决问题
标签: flutter flutter-layout dropdown