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) {
  final Canvas canvas = context.canvas;
  for (Particle particle in particles!) {
    if (particle.alpha == 0.0) continue;
    _paint!.color = options.baseColor.withOpacity(particle.alpha);

    if (_particleImage != null) {
      Rect dst = Rect.fromLTRB(
        particle.cx - particle.radius,
        particle.cy - particle.radius,
        particle.cx + particle.radius,
        particle.cy + particle.radius,
      );
      canvas.drawImageRect(_particleImage!, _particleImageSrc!, dst, _paint!);
    } else
      canvas.drawCircle(
        Offset(particle.cx, particle.cy),
        particle.radius,
        _paint!,
      );
  }
}