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 starPoints = <Offset>[];

  // Calculate star points
  for (int i = 0; i < points * 2; i++) {
    final radius = i.isEven ? outerRadius : innerRadius;
    final angle = (math.pi * i / points) + rotation;
    final x = center.dx + radius * math.cos(angle);
    final y = center.dy + radius * math.sin(angle);
    starPoints.add(Offset(x, y));
  }

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

  final path = Path()..addPolygon(starPoints, 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);
  }
}