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) {
    if (isHorizontal) {
      // Draw horizontal lines
      for (double y = patternOffset.dy; y < size.height; y += spacing) {
        canvas.drawLine(
          Offset(0, y),
          Offset(size.width, y),
          paint,
        );
      }
    } else {
      // Draw vertical lines
      for (double x = patternOffset.dx; x < size.width; x += spacing) {
        canvas.drawLine(
          Offset(x, 0),
          Offset(x, size.height),
          paint,
        );
      }
    }
  } else {
    // Draw a single line at the center
    if (isHorizontal) {
      final centerY = size.height / 2;
      canvas.drawLine(
        Offset(0, centerY),
        Offset(size.width, centerY),
        paint,
      );
    } else {
      final centerX = size.width / 2;
      canvas.drawLine(
        Offset(centerX, 0),
        Offset(centerX, size.height),
        paint,
      );
    }
  }
}