AnimationMixin<T extends StatefulWidget> mixin
Mixin for State classes that host one or more AnimationControllers.
Automatically dispatches AnimationTickMsg to the correct controller and chains the next frame tick if the animation is still running.
Controllers created via createAnimationController are automatically disposed when the State is disposed. Externally created controllers can be registered with registerAnimationController for tick dispatch and automatic disposal.
Usage
class _FadeInState extends State<FadeIn> 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);
}
}
Multiple controllers
You can create as many controllers as you need. Each one gets a unique AnimationController.id so that tick messages are dispatched correctly:
late AnimationController _fadeController;
late AnimationController _slideController;
@override
void initState() {
super.initState();
_fadeController = createAnimationController(
duration: const Duration(milliseconds: 300),
);
_slideController = createAnimationController(
duration: const Duration(milliseconds: 500),
);
_fadeController.addListener(() => setState(() {}));
_slideController.addListener(() => setState(() {}));
}
@override
Cmd? handleInit() {
return Cmd.batch([
_fadeController.forward(),
_slideController.forward(curve: Curves.easeOut),
]);
}
- Superclass constraints
- State<
T>
- State<
Properties
- context ↔ BuildContext
-
The build context for this state.
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- mounted → bool
-
Whether this state is currently mounted in the element tree.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- widget ↔ T
-
The current configuration for this state.
getter/setter pairinherited
Methods
-
build(
BuildContext context) → Widget -
Builds the widget subtree for this state.
inherited
-
createAnimationController(
{double? value, Duration? duration, Duration? reverseDuration, double lowerBound = 0.0, double upperBound = 1.0, int fps = 30, Object? id}) → AnimationController - Creates and registers an AnimationController.
-
didUpdateWidget(
covariant T oldWidget) → Cmd? -
Called when the widget configuration changes.
inherited
-
dispose(
) → void -
Disposes all registered controllers and clears the list.
override
-
handleInit(
) → Cmd? -
Called once when the widget tree is first mounted.
inherited
-
handleIntercept(
Msg msg) → Cmd? -
Called before children during message dispatch.
inherited
-
handleUpdate(
Msg msg) → Cmd? -
Intercepts AnimationTickMsg and dispatches it to the matching
controller via AnimationController.processTick.
override
-
initState(
) → void -
Called when the state is inserted into the tree.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerAnimationController(
AnimationController controller) → void -
Registers an externally-created
controllerfor tick dispatch and automatic disposal. -
setState(
void fn()) → void -
Notifies the framework that this state's internal data has changed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unregisterAnimationController(
AnimationController controller) → bool -
Unregisters a
controllerso it no longer receives tick dispatch and is no longer automatically disposed.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited