如何设置DropdownButton
菜单的背景颜色。我可以自定义出现的Text()
项目,但它们出现在我想要更改颜色的容器中。
这样的东西会起作用:
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),
);
}