drawPartial static method

void drawPartial(
  1. Canvas canvas,
  2. Path path,
  3. Paint paint,
  4. double progress, {
  5. bool reverse = false,
})

Draw progress (0..1) fraction of path using paint.

Internally uses ui.PathMetrics to extract a partial subpath.

Implementation

static void drawPartial(
  Canvas canvas,
  Path path,
  Paint paint,
  double progress, {
  bool reverse = false,
}) {
  if (progress <= 0) return;
  if (progress >= 1) {
    canvas.drawPath(path, paint);
    return;
  }

  final metrics = path.computeMetrics();
  for (final metric in metrics) {
    final len = metric.length * progress;
    final partial = metric.extractPath(0, len);
    canvas.drawPath(partial, paint);
  }
}