答案 0 :(得分:1)
使用DropdownButton
似乎不可能做到这一点,您可以使用PopupMenuButton
来实现,就像这样:
int _selected = 1;
Center(
child: PopupMenuButton(
child: Container(
padding: EdgeInsets.all(8.0),
color: Colors.lightBlueAccent,
child: Text('Selected item: $_selected'),
),
onSelected: (value) => setState(() => _selected = value),
color: Colors.greenAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16.0))),
itemBuilder: (context) {
return [1, 2, 3]
.map((value) => PopupMenuItem(
value: value,
child: Container(
child: Text('$value'),
)))
.toList();
},
),
)