How to change the background color of Popup MenuButton bullet window?

試著忘記壹切 提交于 2019-12-12 11:23:42

问题


I want to change the background color of Popup Menu Button window. What should I do? I hope I can get your help. Thank you.When I change the color of container, some corners cannot change the color.

 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('添加朋友')
                            ],
                          ),
                        ],
                      ))),


回答1:


That background color is based on the Theme , so you can change the color wrapping your PopMenuButton inside Theme and change the cardColor.

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



回答2:


It's kinda ugly, but hey:

PopupMenuButton<String>(
   onSelected: (selected) {},
   icon: Icon(Icons.more_vert, color: Colors.white,),
   itemBuilder: (BuildContext context) {
      ...
   },
), 


来源:https://stackoverflow.com/questions/53662200/how-to-change-the-background-color-of-popup-menubutton-bullet-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!