paint method

  1. @override
void paint(
  1. Canvas canvas,
  2. Size size,
  3. WorldToScreen worldToScreen,
  4. ScreenToWorld screenToWorld,
  5. double scale,
)
override

Called by the canvas to paint this item onto the screen.

The canvas and size are provided by the Flutter framework. Use worldToScreen to translate mathematical coordinates into on-screen pixels.

Implementation

@override
void paint(
  Canvas canvas,
  Size size,
  WorldToScreen worldToScreen,
  ScreenToWorld screenToWorld,
  double scale,
) {
  final position = worldToScreen(x, y);

  canvas.drawCircle(
    position + const Offset(0, 2),
    radius + 1,
    Paint()
      ..color = Colors.black.withOpacity(0.15)
      ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 2.0),
  );

  canvas.drawCircle(position, radius, Paint()..color = color);
  canvas.drawCircle(
    position,
    radius,
    Paint()
      ..color = Colors.white
      ..style = PaintingStyle.stroke
      ..strokeWidth = 1.5,
  );

  if (label != null) {
    final textPainter = TextPainter(
      text: TextSpan(
        text: label,
        style: labelStyle ??
            TextStyle(
              fontSize: 12.5,
              color: color,
              fontWeight: FontWeight.w700,
            ),
      ),
      textDirection: TextDirection.ltr,
    )..layout();

    final labelPos = position + labelOffset;

    textPainter.paint(canvas, labelPos);
  }
}