How can you set the background color of the DropdownButton
menu. I can customize the Text()
items that appear but they appear within a container which I would like to change the color for.
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),
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.