4

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

4

3 回答 3

1

看起来像dropdownColor设置处理这个:

DropdownButton<String>(
  dropdownColor: Colors.blue,

 // ...
}

在此处输入图像描述

.. 多亏了自动完成提供的选项才找到它

于 2020-05-21T19:48:26.800 回答
0

像这样的东西会起作用:

          DropdownMenuItem<int>(
            value: model.id,
            child: SizedBox(
              width: width,
              child: Container(
                color: Colors.green, // 
                child: Text(
                  model.toString(),
                ),
              ),
            ),
          )
        ) 
于 2019-04-12T03:53:56.577 回答
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),
  );
}
于 2019-04-12T07:24:25.650 回答