Animate class

The Flutter Animate library makes adding beautiful animated effects to your widgets simple. It supports both a declarative and chained API. The latter is exposed via the Widget.animate extension, which simply wraps the widget in Animate.

// declarative:
Animate(child: foo, effects: [FadeEffect(), ScaleEffect()])
// equivalent chained API:
foo.animate().fade().scale() // equivalent to above

Effects are always run in parallel (ie. the fade and scale effects in the example above would be run simultaneously), but you can apply delays to offset them or run them in sequence.

All effects classes are immutable, and can be shared between Animate instances, which lets you create libraries of effects to reuse throughout your app.

List<Effect> transitionIn = [
  FadeEffect(duration: 100.ms, curve: Curves.easeOut),
  ScaleEffect(begin: 0.8, curve: Curves.easeIn)
];
// then:
Animate(child: foo, effects: transitionIn)
// or:
foo.animate(effects: transitionIn)

Effects inherit some of their properties (delay, duration, curve) from the previous effect if unspecified. So in the examples above, the scale will use the same duration as the fade that precedes it. All effects have reasonable defaults, so they can be used simply: foo.animate().fade()

Note that all effects are composed together, not run sequentially. For example, the following would not fade in myWidget, because the fadeOut effect would still be applying an opacity of 0:

myWidget.animate().fadeOut(duration: 200.ms).fadeIn(delay: 200.ms)

See SwapEffect for one approach to work around this.

Inheritance
Mixed in types
Available Extensions

Constructors

Animate({Key? key, Widget child = const SizedBox.shrink(), List<Effect>? effects, AnimateCallback? onComplete, AnimateCallback? onPlay, Duration delay = Duration.zero, AnimationController? controller, Adapter? adapter})
Creates an Animate instance that will manage a list of effects and apply them to the specified child.

Properties

adapter Adapter?
An Adapter can drive the animation from an external source (ex. a ScrollController, ValueNotifier, or arbitrary 0-1 value). For more information see Adapter or an adapter class (ChangeNotifierAdapter, ScrollAdapter, ValueAdapter, ValueNotifierAdapter).
final
child Widget
The widget to apply effects to.
final
controller AnimationController?
An external AnimationController can optionally be specified. By default Animate creates its own controller internally.
final
delay Duration
A duration to delay before the animation is started. Unlike Effect.delay, this is not a part of the overall animation, and only runs once if the animation is looped. onPlay is called after this delay.
final
duration Duration
The total duration for all effects.
no setter
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onComplete AnimateCallback?
Called when all effects complete. Provides an opportunity to manipulate the AnimationController (ex. to loop, reverse, etc).
final
onPlay AnimateCallback?
Called when the animation begins playing (ie. after Animate.delay, immediately after AnimationController.forward is called). Provides an opportunity to manipulate the AnimationController (ex. to loop, reverse, stop, etc).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addEffect(Effect effect) Animate
Adds an effect. This is mostly used by Effect extension methods to append effects to an Animate instance.
override
addEffects(List<Effect> effects) Animate
inherited
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<Animate>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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

Static Properties

defaultCurve Curve
Default curve for effects.
getter/setter pair
defaultDuration Duration
Default duration for effects.
getter/setter pair
reparentTypes Map
Widget types to reparent, mapped to a method that handles that type. This is used to make it easy to work with widgets that require specific parents. For example, the Positioned widget, which needs its immediate parent to be a Stack.
getter/setter pair