EffectConfiguration<T extends ParticleConfiguration> constructor

const EffectConfiguration<T extends ParticleConfiguration>({
  1. required T particleConfiguration,
  2. Curve emitCurve = Curves.decelerate,
  3. Duration emitDuration = const Duration(milliseconds: 100),
  4. Curve fadeInCurve = Curves.linear,
  5. Curve fadeOutCurve = Curves.linear,
  6. bool foreground = false,
  7. double maxAngle = 0,
  8. double maxBeginScale = 1,
  9. double maxEndScale = -1,
  10. double maxFadeInThreshold = 0,
  11. double maxFadeOutThreshold = 1,
  12. Offset maxOriginOffset = Offset.zero,
  13. Duration maxParticleLifespan = const Duration(seconds: 1),
  14. double minAngle = 0,
  15. double minBeginScale = 1,
  16. Duration minParticleLifespan = const Duration(seconds: 1),
  17. double minEndScale = -1,
  18. double minFadeInThreshold = 0,
  19. double minFadeOutThreshold = 1,
  20. Offset minOriginOffset = Offset.zero,
  21. Offset origin = const Offset(0.5, 0.5),
  22. int particleCount = 0,
  23. ParticleLayer particleLayer = ParticleLayer.background,
  24. int particlesPerEmit = 1,
  25. Curve scaleCurve = Curves.linear,
  26. Duration startDelay = Duration.zero,
  27. Tag? tag,
  28. Trail trail = const NoTrail(),
})

An abstract class representing the configuration for particle effects, providing a foundation for controlling particle emission, animation, and visual behavior.

The EffectConfiguration class defines various parameters such as emission rate, particle scaling, fading, and lifespans, but it cannot be instantiated directly. Instead, this class is meant to be extended by other concrete effect configurations that implement specific behavior.

Subclasses such as DeterministicEffectConfiguration or RelativisticEffectConfiguration inherit and build upon the parameters defined here, allowing developers to create customized particle effects.

  • particleConfiguration: The general configuration for how particles are emitted and animated.
  • emitCurve: A curve that controls the rate of particle emission over time. Defaults to Curves.decelerate, which gradually slows the emission rate.
  • emitDuration: The interval between each emission of particles. Defaults to 100 milliseconds.
  • fadeInCurve: A curve that controls how particles fade in, typically from transparent to fully visible. Defaults to Curves.linear for a consistent fade-in.
  • fadeOutCurve: A curve that controls how particles fade out, typically from fully visible to transparent. Defaults to Curves.linear for a consistent fade-out.
  • foreground: A boolean value that determines whether the effect should be rendered in the foreground. If true, particles will appear above other visual elements. Defaults to false.
  • maxAngle: The maximum angle (in degrees) for particle trajectory, determining the directional spread of particles. Defaults to 0, meaning no spread.
  • maxBeginScale: The maximum initial scale of the particles, determining their size when first emitted. Defaults to 1.
  • maxEndScale: The maximum final scale of the particles after scaling animations. Defaults to -1, which indicates no scaling applied.
  • maxFadeInThreshold: The highest opacity value at which particles will complete fading in, controlling the visibility of the particles when they fully appear. Defaults to 0.
  • maxFadeOutThreshold: The highest opacity value at which particles start to fade out, controlling when particles begin disappearing. Defaults to 1.
  • maxOriginOffset: The maximum offset from the origin point for particle emission. Defaults to Offset.zero, meaning particles will emit from the specified origin without any additional offset.
  • maxParticleLifespan: The maximum time a particle can exist before disappearing. Defaults to 1 second.
  • minAngle: The minimum angle (in degrees) for particle trajectory, providing control over particle directionality. Defaults to 0.
  • minBeginScale: The minimum initial scale for particles, defining their smallest possible size when emitted. Defaults to 1.
  • minParticleLifespan: The minimum time a particle can exist before disappearing. Defaults to 1 second.
  • minEndScale: The minimum final scale for particles, controlling the smallest size particles can reach after scaling. Defaults to -1, meaning no scaling is applied.
  • minFadeInThreshold: The lowest opacity value at which particles will start to fade in, controlling the visibility of particles as they begin to appear. Defaults to 0.
  • minFadeOutThreshold: The lowest opacity value at which particles will start fading out, controlling when particles begin to disappear. Defaults to 1.
  • minOriginOffset: The minimum offset from the origin point for particle emission. Defaults to Offset.zero.
  • origin: The origin point for particle emission, relative to the top-left corner of the container. Defaults to the center of the container at Offset(0.5, 0.5).
  • particleCount: The total number of particles that will be emitted over the lifetime of the effect. Defaults to 0, meaning no particles will be emitted by default.
  • particleLayer: Specifies the layer on which particles will be rendered. Defaults to ParticleLayer.background, meaning particles will render behind other elements.
  • particlesPerEmit: The number of particles emitted during each emission event. Defaults to 1.
  • scaleCurve: A curve controlling how the particle size changes over time. Defaults to Curves.linear, which means the size change is consistent.
  • startDelay: The delay before particle emission starts after the effect is triggered. Defaults to no delay (Duration.zero).
  • tag: An optional identifier to tag or label the effect for tracking or reference purposes.
  • trail: Specifies the trailing effect that follows each particle, providing additional visual flair. Defaults to NoTrail(), which means no trailing effect will be applied to particles.

Assertions ensure the following conditions are met:

  • minAngle cannot be greater than maxAngle.
  • minBeginScale cannot be greater than maxBeginScale.
  • minEndScale cannot be greater than maxEndScale.
  • minFadeInThreshold cannot be greater than maxFadeInThreshold.
  • minFadeOutThreshold cannot be greater than maxFadeOutThreshold.
  • minOriginOffset cannot be greater than maxOriginOffset.
  • minParticleLifespan cannot be greater than maxParticleLifespan.

Implementation

const EffectConfiguration({
  required this.particleConfiguration,
  this.emitCurve = Curves.decelerate,
  this.emitDuration = const Duration(milliseconds: 100),
  this.fadeInCurve = Curves.linear,
  this.fadeOutCurve = Curves.linear,
  this.foreground = false,
  this.maxAngle = 0,
  this.maxBeginScale = 1,
  this.maxEndScale = -1,
  this.maxFadeInThreshold = 0,
  this.maxFadeOutThreshold = 1,
  this.maxOriginOffset = Offset.zero,
  this.maxParticleLifespan = const Duration(seconds: 1),
  this.minAngle = 0,
  this.minBeginScale = 1,
  this.minParticleLifespan = const Duration(seconds: 1),
  this.minEndScale = -1,
  this.minFadeInThreshold = 0,
  this.minFadeOutThreshold = 1,
  this.minOriginOffset = Offset.zero,
  this.origin = const Offset(0.5, 0.5),
  this.particleCount = 0,
  this.particleLayer = ParticleLayer.background,
  this.particlesPerEmit = 1,
  this.scaleCurve = Curves.linear,
  this.startDelay = Duration.zero,
  this.tag,
  this.trail = const NoTrail(),
})  : assert(minAngle <= maxAngle, 'Min angle can’t be greater than max angle'),
      assert(minBeginScale <= maxBeginScale, 'Begin min scale can’t be greater than begin max scale'),
      assert(minEndScale <= maxEndScale, 'End min scale can’t be greater than end max scale'),
      assert(
        minFadeInThreshold <= maxFadeInThreshold,
        'Min fadeIn threshold can’t be greater than max fadeIn threshold',
      ),
      assert(
        minFadeOutThreshold <= maxFadeOutThreshold,
        'Min fadeOut threshold can’t be greater than max fadeOut threshold',
      ),
      assert(
        minOriginOffset <= maxOriginOffset,
        'Min origin offset can’t be greater than max origin offset',
      ),
      assert(minParticleLifespan <= maxParticleLifespan, 'Min lifespan can’t be greater than max lifespan');