Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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/1/php/242.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
Flutter 获取颤振中圆弧的路径长度_Flutter_Path_Metrics - Fatal编程技术网

Flutter 获取颤振中圆弧的路径长度

Flutter 获取颤振中圆弧的路径长度,flutter,path,metrics,Flutter,Path,Metrics,我目前正在从事一个flatter项目,我试图了解computeMetrics()是如何工作的 Android 我以前实现了一个安卓解决方案来处理ARC,它可以工作。部分实施如下所示: final RectF oval = new RectF(centerX - radiusArc, centerY - radiusArc, centerX + radiusArc, centerY + radiusArc); mPath.addArc(oval, startAngle, sweepA

我目前正在从事一个
flatter项目
,我试图了解
computeMetrics()
是如何工作的

Android

我以前实现了一个安卓解决方案来处理ARC,它可以工作。部分实施如下所示:

   final RectF oval = new RectF(centerX - radiusArc, centerY - radiusArc, centerX + radiusArc, centerY + radiusArc);
    mPath.addArc(oval, startAngle, sweepAngle);

    PathMeasure pm = new PathMeasure(mPath, false);
    float[] xyCoordinate = {startPoint.x, startPoint.y};
    float pathLength = pm.getLength();
颤振

现在我正试图在flatter(
.dart
)中复制同样的东西。因此,我使用以下实现

  final Rect oval = Rect.fromLTRB(centerX - radiusArc, centerY - radiusArc, centerX + radiusArc, centerY + radiusArc);
  mPath.addArc(oval, startAngle, sweepAngle);

  List<num> xyCoordinate = new List<num>(2);
  xyCoordinate[0] = startPoint.x;
  xyCoordinate[1] = startPoint.y;

  List<PathMetric> pm = mPath.computeMetrics().toList();
  double pathLength = pm.iterator.current.length;
final Rect oval=Rect.fromLTRB(centerX-radiusArc,centerY-radiusArc,centerX+radiusArc,centerY+radiusArc);
mPath.addArc(椭圆形、星形、扫掠角);
列表XY坐标=新列表(2);
xycordination[0]=startPoint.x;
XY坐标[1]=起始点y;
List pm=mPath.computeMetrics().toList();
双路径长度=pm.iterator.current.length;
我试图通过几个示例来了解如何获得路径长度,但在使用我的实现时,
pm.iterator.current
null
因此,我无法获得
长度


我假设我错误地理解了
computeMetrics()
的工作原理。

我认为您需要迭代列表并添加每个
PathMetrics
length
,以获得路径长度

double pathLength = 0;
pm.forEach((contour){
  pathLength += contour.length;
});
print(pathLength);
这是因为,正如-

路径由零个或多个轮廓组成

路径度量对象描述单个轮廓的属性, 比如它的长度等等


此外,
computeMetrics()
返回的是单个
pathmetrics
s的可编辑集合,每个对应于构成路径的各个轮廓。因此,为了获得路径的长度,我们需要将列表中每个
PathMetric
(等高线)的长度相加,即
list pm=mPath.computeMetrics().toList()

@bellotas,您确定
pm
为空吗?或者是
pm.iterator.current
为空?对不起,我不知道昨天检查了什么。它不是空的,实际上我得到了一个结果。你能在你的回答中澄清一下所有这些项目的新增内容吗?长度?当然,我已经对答案进行了编辑,包括进一步的解释。