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;

  void drawLines(double angle) {
    canvas.save();
    canvas.translate(size.width / 2, size.height / 2);
    canvas.rotate(angle);
    canvas.translate(-size.width / 2, -size.height / 2);

    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();
  }

  drawLines(angle1);
  drawLines(angle2);
}