drawPattern method

  1. @override
void drawPattern(
  1. Canvas canvas,
  2. Size size
)
override

Draws the pattern once at origin.

Implementation

@override
void drawPattern(Canvas canvas, Size size) {
  final paint = Paint()
    ..color = foregroundColor
    ..strokeWidth = strokeWidth
    ..style = PaintingStyle.stroke;

  canvas.save();

  // Rotate around center
  canvas.translate(size.width / 2, size.height / 2);
  canvas.rotate(angle);
  canvas.translate(-size.width / 2, -size.height / 2);

  // Draw lines to cover the rotated area
  final diagonal =
      math.sqrt(size.width * size.width + size.height * size.height);
  final start = -diagonal;
  final end = diagonal * 2;

  for (double y = start; y < end; y += spacing + strokeWidth) {
    canvas.drawLine(
      Offset(start, y),
      Offset(end, y),
      paint,
    );
  }

  canvas.restore();
}