最近在做flutter相关的app开发,遇到的问题总结一下子,今天说一下文字渐变的实现,flutter 其实是底层使用的opengl图形api,就免不了可以使用shader,文字渐变也是基于此实现的:
代码很简单记录一下:
ShaderMask(
shaderCallback: (rect) {
return const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
transform: GradientRotation(90),
colors: [
Colors.red,
Colors.blue,
Colors.yellow,
Colors.pink
],
stops: [
0.2,
0.3,
0.4,
0.9
]
).createShader(rect);
},
child: Text("Test shader",style: TextStyle(color: Colors.white,fontSize: 48,fontWeight: FontWeight.bold),),
)