extractPathUntilLength method

Path extractPathUntilLength(
  1. Path originalPath,
  2. double length
)

Implementation

Path extractPathUntilLength(
  Path originalPath,
  double length,
) {
  var currentLength = 0.0;
  final path = Path();
  var metricsIterator = originalPath.computeMetrics().iterator;

  while (metricsIterator.moveNext()) {
    var metric = metricsIterator.current;
    var nextLength = currentLength + metric.length;
    final isLastSegment = nextLength > length;
    if (isLastSegment) {
      final remainingLength = length - currentLength;
      final pathSegment = metric.extractPath(0.0, remainingLength);
      path.addPath(pathSegment, Offset.zero);
      break;
    } else {
      final pathSegment = metric.extractPath(0.0, metric.length);
      path.addPath(pathSegment, Offset.zero);
    }
    currentLength = nextLength;
  }

  return path;
}