[英]Customizing the popup menu of a DropdownButton
如何設置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),
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.