[英]How to paint a sector in flutter?
I have to paint a sector of circle in flutter. 我必须在颤动中画一个圆圈。 I used this code 我用了这段代码
canvas.drawArc(
Rect.fromCircle(
center: Offset(size.width / 2, size.height - 50),
radius: size.width / 2),
degrees,
width,
true,
paint);
and it worked fine. 而且效果很好。 However for some inevitable reasons I can't use this method and I have to use the method 但是由于某些不可避免的原因,我无法使用此方法,而必须使用该方法
canvas.drawPath()
For that I need a path but it only has options to create arc and not sector. 为此,我需要一条路径,但是它只能创建弧线,而不能创建扇形。
Path#arcTo
documentation says: Path#arcTo
文档说:
If the
forceMoveTo
argument is false, adds a straight line segment and an arc segment. 如果forceMoveTo
参数为false,则添加直线段和弧段。 [...] The line segment added ifforceMoveTo
is false starts at the current point and ends at the start of the arc. [...]如果forceMoveTo
为false,则添加的forceMoveTo
从当前点开始,并在弧的起点结束。
so this code will draw a segment: 因此此代码将绘制一个段:
Offset center = Offset(250, 250);
Rect rect = Rect.fromCircle(center: center, radius: 200);
Path path = Path()
// set the "current point"
..moveTo(center.dx, center.dy)
..arcTo(rect, pi / 4, pi / 2, false);
canvas.drawPath(path, p);
you should be able to create a path with the same parameters you used in drawArc() 您应该能够使用在drawArc()中使用的相同参数创建路径
try something like 尝试类似
Path.arcTo(Rect.fromCircle(center: Offset(size.width / 2, size.height -
50),radius: size.width / 2), degrees, width, true,)
then use the returned path in canvas.drawPath() 然后在canvas.drawPath()中使用返回的路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.