Flutter PopupMenu更改图标颜色

时间:2019-03-19 11:39:58

标签: colors dart flutter popup icons

如何更改PopupMenuButton上的图标颜色,我已将Theme与iconTheme一起使用,但它不会影响CheckedPopupMenuItem或PopupMenuItem上的图标。

Scaffold(
      backgroundColor: Colors.transparent,
      appBar: AppBar(
        elevation: 0.0,
        backgroundColor: Colors.transparent,
        actions: <Widget>[
          Theme(
            data: Theme.of(context).copyWith(
              cardColor: Colors.indigo,
              iconTheme: IconThemeData(color: Colors.white),
            ),
            child: ListTileTheme(
              iconColor: Colors.white,
              child: PopupMenuButton<String>(
                onSelected: _showCheckedMenuSelections,
                itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
                  CheckedPopupMenuItem<String>(
                    value: _checkedValue1,
                    checked: _showRoles,
                    child: Text(_checkedValue1, style: Theme.of(context).textTheme.body1),
                  ),
                  const PopupMenuDivider(),
                  PopupMenuItem<String>(
                    value: 'Get Link',
                    child: ListTile(
                      leading: Icon(Icons.phonelink),
                      title: Text('Get link', style: Theme.of(context).textTheme.body1),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),

结果如下所示: enter image description here

2 个答案:

答案 0 :(得分:3)

只需这样做

 appBar: AppBar(
          iconTheme: IconThemeData(color: Colors.white, size: 10.0),
          elevation: 4.0,
          backgroundColor: Colors.black,
)

答案 1 :(得分:0)

您可以将Icon小部件包装在IconButton内,该小部件提供color属性来更改图标颜色。下面的示例代码:

value: 'Get Link',
    child: ListTile(
    leading: IconButton(
      icon: Icon(Icons.phonelink,
      color: Colors.blue,),
      onPressed: () {},
    ),
    title: Text('Get link', style: Theme.of(context).textTheme.body1),
    ),

enter image description here