如何更改Popup MenuButton项目符号窗口的背景颜色?

时间:2018-12-07 01:55:42

标签: 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

4 个答案:

答案 0 :(得分:2)

该背景色基于send_task,因此您可以更改将Theme包裹在PopMenuButton内的颜色并更改Theme

cardColor

答案 1 :(得分:1)

有点丑陋,但是:

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

答案 2 :(得分:0)

您可以使用select * from ( SELECT *, 6371 * 2 * asin(sqrt(POW(sin(({lat} - radians(a.latitude)) / 2), 2) + cos({lat}) * cos(radians(a.latitude)) * POW(sin(({lon} - radians(a.longitude)) / 2), 2))) as distance FROM service s JOIN provider p ON s.provider_id = p.id JOIN address a ON p.address_id = a.id WHERE p.status = True ) x WHERE distance < 10 ORDER BY distance 更改背景颜色,而不必将其包装在新主题中。

答案 3 :(得分:0)

Center(
      child: Theme(
        data: Theme.of(context).copyWith(
          cardColor: Colors.red,
        ),
        child: PopupMenuButton(
          child: Text("Show Popup Menu"),
          itemBuilder: (context) => [
                PopupMenuItem(
                  child: Text("InduceSmile.com"),
                ),
                PopupMenuItem(
                  child: Text("Flutter.io"),
                ),
                PopupMenuItem(
                  child: Text("Google.com"),
                ),
              ],
        ),
      ),

这很好。