paint method

  1. @override
void paint(
  1. PaintingContext context,
  2. Offset offset
)
override

Called each time the AnimatedBackground needs to repaint.

The canvas provided in the context is already offset by the amount specified in offset, however the parameter is provided to make the signature of the methods uniform.

Implementation

@override
void paint(PaintingContext context, Offset offset) {
  var canvas = context.canvas;
  Paint paint = Paint()
    ..strokeWidth = 3.0
    ..strokeCap = StrokeCap.round
    ..style = PaintingStyle.stroke;

  for (var bubble in bubbles!) {
    paint.color = bubble.color!;
    if (!bubble.popping) {
      canvas.drawCircle(bubble.position, bubble.radius!, paint);
    } else {
      final double radiusSqrt = bubble.radius! * sqrtInverse;
      final double targetRadiusSqrt = bubble.targetRadius * sqrtInverse;
      canvas.drawLine(
        bubble.position + Offset(radiusSqrt, radiusSqrt),
        bubble.position + Offset(targetRadiusSqrt, targetRadiusSqrt),
        paint,
      );
      canvas.drawLine(
        bubble.position + Offset(radiusSqrt, -radiusSqrt),
        bubble.position + Offset(targetRadiusSqrt, -targetRadiusSqrt),
        paint,
      );
      canvas.drawLine(
        bubble.position + Offset(-radiusSqrt, radiusSqrt),
        bubble.position + Offset(-targetRadiusSqrt, targetRadiusSqrt),
        paint,
      );
      canvas.drawLine(
        bubble.position + Offset(-radiusSqrt, -radiusSqrt),
        bubble.position + Offset(-targetRadiusSqrt, -targetRadiusSqrt),
        paint,
      );
      canvas.drawLine(bubble.position + Offset(0.0, bubble.radius!),
          bubble.position + Offset(0.0, bubble.targetRadius), paint);
      canvas.drawLine(bubble.position + Offset(0.0, -bubble.radius!),
          bubble.position + Offset(0.0, -bubble.targetRadius), paint);
      canvas.drawLine(bubble.position + Offset(bubble.radius!, 0.0),
          bubble.position + Offset(bubble.targetRadius, 0.0), paint);
      canvas.drawLine(bubble.position + Offset(-bubble.radius!, 0.0),
          bubble.position + Offset(-bubble.targetRadius, 0.0), paint);
    }
  }
}