Changing Background Color Of Image in Flutter

前端 未结 5 2169
陌清茗
陌清茗 2021-01-15 03:10

Can we Change the background color on an Image in Flutter? Like in this Image I want to change the pink color background color to something else.

5条回答
  •  甜味超标
    2021-01-15 03:46

    In my case, I was trying to color a Transparent PNG

    I tried this solution and it's working.

    Using ShaderMask class (https://docs.flutter.io/flutter/widgets/ShaderMask-class.html)

    Example:

    ShaderMask(
      child: Image(
        image: AssetImage("assets/cat.png"),
      ),
      shaderCallback: (Rect bounds) {
        return LinearGradient(
          colors: [Colors.blue, Colors.lightBlue],
          stops: [
            0.0,
            0.5,
          ],
        ).createShader(bounds);
      },
      blendMode: BlendMode.srcATop,
    )
    

提交回复
热议问题