paint method

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

Paints the shape on the given canvas.

This method must be implemented by all concrete shape painters. It should handle the actual drawing logic for the specific shape.

canvas is the canvas to paint on. size is the size of the canvas.

Implementation

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

  if (repeatPattern) {
    // Draw vertical grid lines
    for (double x = patternOffset.dx; x < size.width; x += spacing) {
      canvas.drawLine(
        Offset(x, 0),
        Offset(x, size.height),
        paint,
      );
    }

    // Draw horizontal grid lines
    for (double y = patternOffset.dy; y < size.height; y += spacing) {
      canvas.drawLine(
        Offset(0, y),
        Offset(size.width, y),
        paint,
      );
    }
  } else {
    // Draw a single grid cell at the center
    final centerX = size.width / 2;
    final centerY = size.height / 2;
    final halfSpacing = spacing / 2;

    // Vertical line
    canvas.drawLine(
      Offset(centerX, centerY - halfSpacing),
      Offset(centerX, centerY + halfSpacing),
      paint,
    );

    // Horizontal line
    canvas.drawLine(
      Offset(centerX - halfSpacing, centerY),
      Offset(centerX + halfSpacing, centerY),
      paint,
    );
  }
}