flutter - 如何更改 Popup MenuButton 弹窗的背景颜色?

标签 flutter flutter-layout

我想更改弹出菜单按钮窗口的背景颜色。我应该怎么办?我希望我能得到你的帮助。谢谢。当我改变容器的颜色时,有些角落不能改变颜色。

 new IconButton(
            icon: new Icon(
              Icons.search,
              color: Colors.white,
            ),
            onPressed: () {},
          ),
          new PopupMenuButton(
            offset: const Offset(0.0, 60.0),
            icon: new Icon(Icons.add, color: Colors.white),
            itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
                  new PopupMenuItem<String>(
                      value: '选项一的值',
                      child: new Container(
                          color: Colors.red,
                          child: new Column(
                            children: <Widget>[
                              new Row(
                                children: <Widget>[
                                  new Image.asset(defaultAvatar,
                                      width: 30.0, height: 30.0),
                                  new Text('发起群聊')
                                ],
                              ),
                            ],
                          ))),
                  new PopupMenuItem<String>(
                      value: '选项一的值',
                      child: new Container(
                          child: new Column(
                        children: <Widget>[
                          new Row(
                            children: <Widget>[
                              new Image.asset(defaultAvatar,
                                  width: 30.0, height: 30.0),
                              new Text('添加朋友')
                            ],
                          ),
                        ],
                      ))),

enter image description here

最佳答案

该背景颜色基于 Theme ,因此您可以更改 PopMenuButtonTheme 的颜色并更改 卡片颜色.

          Theme(
                data: Theme.of(context).copyWith(
                  cardColor: Colors.red,
                ),
                child: new PopupMenuButton(
                       ...

关于flutter - 如何更改 Popup MenuButton 弹窗的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53662200/

相关文章:

flutter 。将屏幕更改为横向,它会自动变回纵向

android - 如何在 Flutter 中为按钮添加渐变?

listview - 用列/行小部件包裹小部件后屏幕消失

flutter - 如何计算Flutter GridView子级的默认高度和宽度?

flutter - 有没有办法在 BlocListener 初始化后立即触发它?

Flutter,如何创建嵌入文本的边框?

flutter - 如何从 json 列表中返回对象?

flutter - 如何将 ScrollController 添加到 SliverList flutter

flutter - 如何在 Flutter 中构建静态 datePicker 小部件,而无需在之前按下按钮

python - 如何通过抖动控制Rpi的GPIO引脚?