getNonSolidPath method

Path getNonSolidPath(
  1. Path source, {
  2. TextDirection? textDirection,
})
inherited

Calculates the path for a non-solid outline style (e.g., dashed).

This method takes a source path and transforms it based on the effective side's style and width to create a path representing the non-solid outline.

Implementation

Path getNonSolidPath(Path source, {TextDirection? textDirection}) {
  final Path dest = Path();
  final sideStyle = effectiveSide.effectiveStyle;
  final sideWidth = effectiveSide.effectiveWidth;
  for (final PathMetric metric in source.computeMetrics()) {
    int index = 0;
    double distance = 0;
    bool draw = true;
    while (distance < metric.length) {
      if (index >= sideStyle.pattern.length) {
        index = 0;
      }
      final double mul = sideStyle.absolute ? 1 : sideWidth;
      final double len = sideStyle.pattern[index++] * mul;
      if (draw) {
        dest.addPath(
          metric.extractPath(distance, distance + len),
          Offset.zero,
        );
      }
      distance += len;
      draw = !draw;
    }
  }

  return dest;
}