dashPath function

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

Came from flutter_path_drawing library. 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);
  // TODO(imaNNeo): Is there some way to determine how much of a path would be visible today?

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

  return dest;
}