paintOnPath method

void paintOnPath(
  1. Canvas canvas,
  2. Size size,
  3. Path path, {
  4. PatternScaleBehavior patternScaleBehavior = PatternScaleBehavior.container,
  5. Rect? customRect,
})

Paint the Pattern on a Path.

If PatternScaleBehavior.customRect is specified, you must also provide a customRect to scale the Pattern to.

Implementation

void paintOnPath(Canvas canvas, Size size, Path path,
    {PatternScaleBehavior patternScaleBehavior =
        PatternScaleBehavior.container,
    Rect? customRect}) {
  canvas.save();
  canvas.clipPath(path);
  switch (patternScaleBehavior) {
    case PatternScaleBehavior.container:
      final Rect boundsRect = path.getBounds();
      final pathW = boundsRect.width,
          pathH = boundsRect.height,
          pathX = boundsRect.left,
          pathY = boundsRect.top;
      paintWithPattern(canvas, pathX, pathY, pathW, pathH);
      break;
    case PatternScaleBehavior.canvas:
      paintOnCanvas(canvas, size);
      break;
    case PatternScaleBehavior.customRect:
      (customRect != null)
          ? paintWithPattern(canvas, customRect.left, customRect.top,
              customRect.width, customRect.height)
          : paintOnCanvas(canvas, size);
      break;
  }
  canvas.restore();
}