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 center = Offset(size.width / 2, size.height / 2);
  final points = <Offset>[];

  // Calculate polygon points
  for (int i = 0; i < sides; i++) {
    final angle = (2 * math.pi * i / sides) + rotation;
    final x = center.dx + radius * math.cos(angle);
    final y = center.dy + radius * math.sin(angle);
    points.add(Offset(x, y));
  }

  // Draw the filled polygon
  final paint = Paint()
    ..color = color
    ..style = PaintingStyle.fill;

  final path = Path()..addPolygon(points, true);
  canvas.drawPath(path, paint);

  // Draw the border if specified
  if (strokeWidth != null && strokeColor != null) {
    final borderPaint = Paint()
      ..color = strokeColor!
      ..style = PaintingStyle.stroke
      ..strokeWidth = strokeWidth!;

    canvas.drawPath(path, borderPaint);
  }
}