render method

  1. @override
void render(
  1. Canvas canvas
)

Should render this Particle to given Canvas.

Default behavior is empty, so that it's not required to override this in a Particle that renders nothing and serve as a behavior container.

Implementation

@override
void render(Canvas canvas) {
  final remainingLife = lifespan - _elapsed;

  double opacity;

  if (remainingLife <= fadeOutDuration) {
    // Start fading out
    opacity = (remainingLife / fadeOutDuration).clamp(0.0, 1.0);
  } else {
    // Fully opaque
    opacity = 1.0;
  }

  final paint = Paint()
    ..color = baseColor.withOpacity(opacity)
    ..style = PaintingStyle.fill;

  canvas.drawCircle(position.toOffset(), radius, paint);
}