自定义DropdownButton的弹出菜单

问题描述 投票:2回答:2

如何设置DropdownButton菜单的背景颜色。我可以自定义出现的Text()项目,但它们出现在我想要更改颜色的容器中。

drop-down-menu flutter flutter-layout dropdownbutton
2个回答
0
投票

这样的东西会起作用:

          DropdownMenuItem<int>(
            value: model.id,
            child: SizedBox(
              width: width,
              child: Container(
                color: Colors.green, // 
                child: Text(
                  model.toString(),
                ),
              ),
            ),
          )
        ) 

0
投票
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),
  );
}
© www.soinside.com 2019 - 2024. All rights reserved.