dashPath function

Path dashPath(
  1. Path source, {
  2. required CircularIntervalList<double> dashArray,
  3. DashOffset? dashOffset,
})

Creates a new path that is drawn from the segments of source.

Dash intervals are controled by the dashArray - see CircularIntervalList for examples.

dashOffset specifies an initial starting point for the dashing.

Passing a source that is an empty path will return an empty path.

Implementation

Path dashPath(
  Path source, {
  required CircularIntervalList<double> dashArray,
  DashOffset? dashOffset,
}) {
  assert(dashArray != null); // ignore: unnecessary_null_comparison

  dashOffset = dashOffset ?? const DashOffset.absolute(0.0);

  final Path dest = Path();
  for (final PathMetric metric in source.computeMetrics()) {
    double distance = dashOffset._calculate(metric.length);
    bool draw = true;
    while (distance < metric.length) {
      final double len = dashArray.next;
      if (draw) {
        dest.addPath(metric.extractPath(distance, distance + len), Offset.zero);
      }
      distance += len;
      draw = !draw;
    }
  }

  return dest;
}