首页 文章

Flutter更改FloatingActionButton的子图标颜色

提问于
浏览
1

我是 Flutter 的新手,并且正在尝试更改FloatingActionButton的子图标颜色 . 儿童图标颜色默认为白色 .

我该怎么改变?

以下是我所使用的代码 .

floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
        backgroundColor: Colors.yellow,

      ), // This trailing comma makes auto-formatting nicer for build methods.
    );

谢谢 .

2 回答

  • 4

    你可以包装 IconTheme

    child: new IconTheme(
        data: new IconThemeData(
            color: Colors.yellow), 
        child: new Icon(Icons.add),
    ),
    

    Theme 其中 iconTheme 按您希望的方式设置

    (未测试)

  • 2

    要更改子图标的颜色,您必须在Icon()小部件中设置颜色 .

    在这里,我分享了我设置了红色的代码片段 .

    floatingActionButton: FloatingActionButton(
            tooltip: 'Increment',
            child: new Icon(Icons.add, color: Colors.red,),
            backgroundColor: Colors.yellow,
          ),
    

相关问题