Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/src/effects/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ abstract class Effect<T extends AnimatedParticle> {
/// Terminates the effect when all emissions are complete and no particles remain active.
void _killEffectWhenOver() {
if (_isEmissionOver()) {
kill();
dispose();
}
}

Expand Down Expand Up @@ -245,10 +245,11 @@ abstract class Effect<T extends AnimatedParticle> {
///
/// This method transitions the effect to the killed state, stops emission,
/// and clears all active particles and callbacks.
void kill() {
void dispose() {
stop(cancel: true);
_updateState(EffectState.killed);
postEffectCallback = null;
particleConfiguration.dispose();
}

/// Helper method to generate a random distance
Expand Down
4 changes: 4 additions & 0 deletions lib/src/particles/particle_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ class ParticleConfiguration {

/// Effect to trigger once particle travel is over.
final Effect<AnimatedParticle> Function(Particle, Size surfaceSize)? postEffectBuilder;

void dispose() {
shape.dispose();
}
}
18 changes: 18 additions & 0 deletions lib/src/particles/shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ sealed class Shape {
Particle particle,
ui.Image defaultShapes,
);

void dispose();
}

/// Represents a circular shape for rendering particles.
Expand Down Expand Up @@ -67,6 +69,9 @@ class CircleShape extends Shape {
final color = particle.color;
return (image: defaultShapes, rect: rect, transform: transform, color: color);
}

@override
void dispose() {}
}

/// Represents a shape based on an image for rendering particles.
Expand Down Expand Up @@ -105,6 +110,11 @@ class ImageShape extends Shape {
final color = particle.color;
return (image: image, rect: rect, transform: transform, color: color);
}

@override
void dispose() {
image.dispose();
}
}

/// Represents a shape based on an asset image for rendering particles.
Expand Down Expand Up @@ -159,6 +169,11 @@ class ImageAssetShape extends Shape {
}
return imageShape.computeTransformation(particle, defaultShapes);
}

@override
void dispose() {
_imageShape?.dispose();
}
}

/// Represents a square shape for rendering particles.
Expand Down Expand Up @@ -191,4 +206,7 @@ class SquareShape extends Shape {
final color = particle.color;
return (image: defaultShapes, rect: rect, transform: transform, color: color);
}

@override
void dispose() {}
}