我必须在 flutter 中绘制一个圆圈。我使用了这段代码
canvas.drawArc(
Rect.fromCircle(
center: Offset(size.width / 2, size.height - 50),
radius: size.width / 2),
degrees,
width,
true,
paint);
而且效果很好。但是由于一些不可避免的原因我不能使用这个方法,我必须使用这个方法
canvas.drawPath()
为此,我需要一条路径,但它只有创建弧形而不是扇形的选项。
最佳答案
Path#arcTo
文档说:
If the
forceMoveTo
argument is false, adds a straight line segment and an arc segment. [...] The line segment added ifforceMoveTo
is false starts at the current point and ends at the start of the arc.
因此这段代码将绘制一个线段:
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);
关于dart - 如何在 flutter 中绘制一个扇区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54926795/