[英]Customizing the popup menu of a DropdownButton
How can you set the background color of the DropdownButton
menu.如何设置
DropdownButton
菜单的背景颜色。 I can customize the Text()
items that appear but they appear within a container which I would like to change the color for.我可以自定义出现的
Text()
项目,但它们出现在我想更改颜色的容器中。
Something like this will work:像这样的事情会起作用:
DropdownMenuItem<int>(
value: model.id,
child: SizedBox(
width: width,
child: Container(
color: Colors.green, //
child: Text(
model.toString(),
),
),
),
)
)
int _value = 0;
Widget _buildDropdown() {
return DropdownButton(
value: _value,
items: [
DropdownMenuItem(
value: 0,
child: Container(
color: Colors.blue, // you need this
child: Text("Zero"),
width: 100,
alignment: Alignment.center,
),
),
DropdownMenuItem(
value: 1,
child: Container(
color: Colors.green, // you need this
child: Text("One"),
width: 100,
alignment: Alignment.center,
),
),
],
onChanged: (value) => setState(() => _value = value),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.