AnimationController class

A TEA-native animation controller.

Unlike Flutter's AnimationController which relies on SchedulerBinding and Ticker for frame scheduling, this controller integrates with the TEA (The Elm Architecture) message loop used by artisanal.

How it works

  1. Calling forward, reverse, animateTo, or repeat returns a Cmd that schedules the first animation frame tick via Cmd.tick.
  2. When the tick fires, the TEA loop delivers an AnimationTickMsg to State.handleUpdate (or AnimationMixin handles it automatically).
  3. The handler calls processTick with the message's timestamp.
  4. processTick updates value and status, notifies listeners, and returns another Cmd to schedule the next tick — or null if done.
  5. The animation self-terminates by not returning a Cmd when complete.

Usage

class _MyState extends State<MyWidget> with AnimationMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = createAnimationController(
      duration: const Duration(milliseconds: 300),
    );
    _controller.addListener(() => setState(() {}));
  }

  @override
  Cmd? handleInit() => _controller.forward();

  @override
  Widget build(BuildContext context) {
    return Opacity(opacity: _controller.value, child: widget.child);
  }
}
Inheritance
Mixed-in types

Constructors

AnimationController({double? value, Duration? duration, Duration? reverseDuration, double lowerBound = 0.0, double upperBound = 1.0, int fps = 30, Object? id})
Creates an animation controller.

Properties

duration Duration?
The length of time this animation should last when going forward.
getter/setter pair
fps int
Target frame rate for animation ticks (frames per second).
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
id Object
The unique identity of this controller, used to match tick messages.
no setter
isAnimating bool
Whether this animation is currently running (forward or reverse).
no setterinherited
isCompleted bool
Whether this animation is stopped at the end.
no setterinherited
isDismissed bool
Whether this animation is stopped at the beginning.
no setterinherited
lowerBound double
The lowest value this animation can have.
final
reverseDuration Duration?
The length of time this animation should last when going in reverse.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
status AnimationStatus
The current status of this animation.
no setteroverride
upperBound double
The highest value this animation can have.
final
value double
The current value of the animation.
no setteroverride

Methods

addListener(void listener()) → void
Register listener to be called when the object notifies.
inherited
addStatusListener(AnimationStatusListener listener) → void
Registers a listener that is called when the animation status changes.
override
animateBack(double target, {Duration? duration, Curve curve = Curves.linear}) Cmd
Animates backward to target with optional duration and curve overrides.
animateTo(double target, {Duration? duration, Curve curve = Curves.linear}) Cmd
Animates to target with optional duration and curve overrides.
dispose() → void
Releases resources held by this controller.
override
drive<U>(Animatable<U> child) Animation<U>
Chains this animation with an Animatable to produce a derived Animation of a different type.
inherited
forward({double? from, Curve curve = Curves.linear}) Cmd
Starts animating forward (toward upperBound).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Notify all registered listeners.
inherited
processTick(DateTime now) Cmd?
Processes a frame tick. Call this from State.handleUpdate when an AnimationTickMsg with a matching controllerId is received.
removeListener(void listener()) → void
Remove a previously registered listener.
inherited
removeStatusListener(AnimationStatusListener listener) → void
Removes a previously registered status listener.
override
repeat({double? min, double? max, bool reverse = false, Duration? period, Curve curve = Curves.linear}) Cmd
Repeats the animation indefinitely between min and max.
reset() → void
Resets the animation to lowerBound with AnimationStatus.dismissed.
reverse({double? from, Curve curve = Curves.linear}) Cmd
Starts animating backward (toward lowerBound).
stop({bool canceled = false}) → void
Stops the animation at its current value.
throwIfDisposed() → void
Throws StateError if this notifier has already been disposed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited