I have a Paint
object and I'm trying to use it to paint an Arc Gradient using canvas.drawArc
, but the only way to do this (at least according to my research) is to use a Shader
, but to get a Shader
from a Gradient
object, you have to use Gradient.createShader(Rect rect)
, which takes a rectangle. My question is, is there any way to create a shader for an Arc and not a Rectangle? Here's what I have so far for reference:
Paint paint = new Paint()
..color = bgColor
..strokeCap = StrokeCap.round
..strokeWidth = 3.0
..style = PaintingStyle.stroke
..shader = new Gradient.radial(size.width / 2.0, size.height / 2.0, size.height / 3.0, Colors.transparent, timerColor, TileMode.mirror).createShader(/* I don't have a rect object */);
canvas.drawArc(..., paint);
See Question&Answers more detail:os