在着色器蒙版上对线性渐变进行动画处理

时间:2020-02-21 22:57:13

标签: flutter flutter-animation

嗨,我正在使用着色器蒙版中的线性渐变将渐变应用于以下图标代码:

child: LinearGradientMask(
          colors: [Color(0xFF21A9E4), Color(0xFF6152E7)],
          child: Icon(
            Icons.power_settings_new,
            size: 90,
            color: Color(0xFFFFFFFF),
          ),
        )
class LinearGradientMask extends StatelessWidget {
  LinearGradientMask({this.child, this.colors});

  final Widget child;
  final List<Color> colors;

  @override
  Widget build(BuildContext context) {
    return ShaderMask(
      shaderCallback: (bounds) => LinearGradient(
        begin: FractionalOffset.topLeft,
        end: FractionalOffset.bottomRight,
        colors: colors,
        tileMode: TileMode.mirror,
      ).createShader(bounds),
      child: child,
    );
  }
}

我是动画制作人员的新手,我希望能够更新状态变量中的颜色并获取图标以在更改渐变时为其设置动画。该按钮如下所示:

Button image

0 个答案:

没有答案