用抖动填充图像的背景色

时间:2020-04-20 12:15:12

标签: flutter flutter-layout flutter-widget

是否可以向图标图像添加背景色?我正在使用以下代码来呈现图标。

      Icon(
            Icons.check_circle_outline,
            size: 35.0,
          )

我要在绘制图像时像下面这样输出

enter image description here

3 个答案:

答案 0 :(得分:2)

如果您尝试获得与图片完全相同的图标,则这是不可能的。图标check_circle_outline如下所示:

enter image description here

因此,您在一个图标中都有一个选中标记和一个圆圈。您只想更改图标的一部分(在您的情况下为圆圈)

但是,如果您只想在图标后面添加背景色,则可以像Viren所说的那样做:

Container(
  color: Colors.blue,
  child: Icon(
    Icons.check_circle_outline,
    size: 35.0,
  ),
)

enter image description here

如果您想要与图片完全相同的图标,请使用另一个图标check圆圈和以下代码段:

ClipOval(
  child: Container(
    color: Colors.green,
    child: Icon(        
      Icons.check,
      color: Colors.white,
      size: 35.0,
    ),
  ),
);

enter image description here

答案 1 :(得分:0)

怎么样?

Container(
  color: Colors.blue,
  child: Icon(
    Icons.check_circle_outline,
    size: 35.0,
  ),
),

enter image description here

答案 2 :(得分:0)

以下解决方案提供准确的输出

Container(
          color: Colors.blue,
          padding: EdgeInsets.all(5),
          child: ClipOval(
            child: Container(
              color: Colors.green,
              child: Icon(
                Icons.check,
                color: Colors.white,
                size: 30,
              ),
            ),
          ),
        )

输出:

enter image description here