如何在颤振中为图标填充颜色

How to fill color in the icon in flutter

我是 flutter 的新手。我在应用程序中使用多个主题(即暗模式)。所以,当我们在不同的主题中使用图标时,会自动根据主题取背景色。我想要主题的背景颜色,但不是在图标里面。

示例: 我在深色主题中使用 youtube 的图标,如下所示,

但我想在下面点赞,

我正在使用

Icon(
    FontAwesomeIcons.youtube,
    color: Colors.red
)

那么如何给这个图标填充白色呢? (或者您也可以建议我以适当和更好的方式执行此操作)

(所以,我可以在每个主题中使用白色填充图标)

您可以使用 Stack 在您的图标下方放置填充的 Container,如下所示:

Stack(children: <Widget>[
      Positioned.fill(
        child: Container(
          margin: EdgeInsets.all(5), // Modify this till it fills the color properly
          color: Colors.white, // Color
        ),
      ),
      Icon(
        FontAwesomeIcons.youtube, // Icon
        color: Colors.red,
      ),
      ),
    ])

由于它是一个容器,您还可以修改它的形状,以防出现普通正方形无济于事的随机图标形状:P

我尝试在 DartPad 上用绿色填充图标 play_circle_filled,它给了我这个: