SpoilerController class
A base controller that manages a "spoiler" effect, which involves:
- A set of "particles" (positions, movement, lifespan).
- An optional fade animation (a radial reveal or cover based on
_fadeCenter
). - Regular particle updates (re-spawning or random movement).
This class does not handle wave animations (see SpoilerSpotsController for that).
USAGE:
- Instantiate with a TickerProvider, which is typically your State object.
- Call initializeParticles to set up the bounding path, the configuration (e.g. fade, color, speed).
- Use toggle, enable, or disable to turn the spoiler effect on/off.
- In your painting code, call drawParticles to render the moving particles.
- Inheritance
-
- Object
- ChangeNotifier
- SpoilerController
- Implementers
Constructors
- SpoilerController.new({required TickerProvider vsync})
- Creates a new SpoilerController.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isEnabled → bool
-
True if the spoiler effect is currently on (particles + fade).
no setter
- isFading → bool
-
True if the fade animation is active.
no setter
- isInitialized → bool
-
True if we have at least one particle.
no setter
-
particles
→ List<
Particle> -
Internal list of active particles in the spoiler region.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- spoilerBounds → Rect
-
The bounding rectangle for the spoiler region.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
createClipPath(
Size size) → Path - A path function that clips only the circular fade area if there’s a non-zero fade radius.
-
createSplashPathMaskClipper(
Size size) → Path -
disable(
) → void - Turn off the spoiler effect: fade from 1→0, then stop the animation entirely.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
drawParticles(
Canvas canvas) → void -
Draws the current set of particles via
canvas.drawRawAtlas
. -
enable(
) → void - Turn on the spoiler effect: show the fade from 0→1 (if configured), and restart the particle animation.
-
initializeParticles(
Path path, SpoilerConfig config) → void -
Sets up the spoiler region, the bounding path, and initializes all particles.
If
config.isEnabled
is true, the spoiler is turned on, and we start the particle animation. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
onEnabledChanged(
bool value) → void -
Called by toggle after setting
_fadeCenter
. Ifvalue
is true, calls enable. Otherwise, disable. -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
toggle(
Offset fadeOffset) → bool -
Toggle the spoiler effect on/off. Optional
fadeOffset
for the radial center. -
toString(
) → String -
A string representation of this object.
inherited
-
updateConfiguration(
SpoilerConfig config) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited