如何更改 TextButton.icon 中的颜色

Sai*_*imi 2 flutter iconbutton

我想要一个带有文本的图标,所以我使用了TextButton.icon但我无法更改文本或图标的颜色!如果有人有解决方案,请建议这是我的代码:

SizedBox(height: 8,),
        TextButton.icon(
          icon: Icon(Icons.delete),
          label: Text('delete'),

          onPressed: (){},
        ),
Run Code Online (Sandbox Code Playgroud)

Emm*_*tey 7

您可以在 TextButton 的样式上使用 TextButton.stylefrom。在这种方法中,您可以使用primary来设置图标和标签的颜色。如果您想为图标设置其他颜色,可以在 Icon 中设置图标颜色。

TextButton.icon(
   onPressed:(){},
   style: TextButton.styleFrom(
      foregroundColor: Colors.blue,
   ),
   icon: Icon(Icons.ac_unit, color: Colors.red),
   label: Text("label"),
 )
Run Code Online (Sandbox Code Playgroud)