AnimatedWidget class abstract

A widget that rebuilds when the given Listenable changes value.

AnimatedWidget is most commonly used with Animation objects, which are Listenable, but it can be used with any Listenable, including ChangeNotifier and ValueNotifier.

AnimatedWidget is most useful for widgets that are otherwise stateless. To use AnimatedWidget, subclass it and implement the build function.

This code defines a widget called Spinner that spins a green square continually. It is built with an AnimatedWidget.
link

To create a local project with this code sample, run:
flutter create --sample=widgets.AnimatedWidget.1 mysample

For more complex case involving additional state, consider using AnimatedBuilder or ListenableBuilder.

Relationship to ImplicitlyAnimatedWidgets

AnimatedWidgets (and their subclasses) take an explicit Listenable as argument, which is usually an Animation derived from an AnimationController. In most cases, the lifecycle of that AnimationController has to be managed manually by the developer. In contrast to that, ImplicitlyAnimatedWidgets (and their subclasses) automatically manage their own internal AnimationController making those classes easier to use as no external Animation has to be provided by the developer. If you only need to set a target value for the animation and configure its duration/curve, consider using (a subclass of) ImplicitlyAnimatedWidgets instead of (a subclass of) this class.

Common animated widgets

A number of animated widgets ship with the framework. They are usually named FooTransition, where Foo is the name of the non-animated version of that widget. The subclasses of this class should not be confused with subclasses of ImplicitlyAnimatedWidget (see above), which are usually named AnimatedFoo. Commonly used animated widgets include:

Inheritance
Implementers

Constructors

AnimatedWidget({Key? key, required Listenable listenable})
Creates a widget that rebuilds when the given listenable changes.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
listenable Listenable
The Listenable to which this widget is listening.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Widget
Override this method to build widgets that depend on the state of the listenable (e.g., the current value of the animation).
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<AnimatedWidget>
Subclasses typically do not override this method.
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.
override
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