Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 如何在颤振中绘制扇形图?_Dart_Flutter - Fatal编程技术网

Dart 如何在颤振中绘制扇形图?

Dart 如何在颤振中绘制扇形图?,dart,flutter,Dart,Flutter,我必须在颤振中画一个扇形圆圈。我用了这个密码 canvas.drawArc( Rect.fromCircle( center: Offset(size.width / 2, size.height - 50), radius: size.width / 2), degrees, width, true, paint); 而且效果很好。然而,由于一些不可避免的原因,我不能使用这种方法,我必须使用这种方法 canvas.dra

我必须在颤振中画一个扇形圆圈。我用了这个密码

canvas.drawArc(
    Rect.fromCircle(
        center: Offset(size.width / 2, size.height - 50),
        radius: size.width / 2),
    degrees,
    width,
    true,
    paint);
而且效果很好。然而,由于一些不可避免的原因,我不能使用这种方法,我必须使用这种方法

canvas.drawPath()

为此,我需要一个路径,但它只有创建弧而不是扇区的选项。

您应该能够使用在drawArc()中使用的相同参数创建路径

试试像这样的东西

Path.arcTo(Rect.fromCircle(center: Offset(size.width / 2, size.height - 
50),radius: size.width / 2), degrees, width, true,)
然后在canvas.drawPath()中使用返回的路径

path#arcTo
文档说明:

如果
forceMoveTo
参数为false,则添加一条直线 线段和圆弧段。 [...] 如果
forceMoveTo
为假,则添加的线段从 当前点并在弧的起点处结束

因此,该代码将绘制一段:

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);

您是否检查了
Path
文档?它没有任何与“arc”相关的方法吗?它有,但它给出了arc而不是扇区。所以调用
Path\moveTo()
Path.close()
移动到哪里?我用中心的坐标调用了moveTo,但还是一样的。等等,谢谢……我用直线到中心的方式代替了moveTo,它工作了……thanksit给出了一个圆弧,而不是一个扇形。