AnimatedWidget classabstract
A widget that rebuilds when the givenListenable changes value.
AnimatedWidget is most commonly used withAnimation objects, which areListenable, but it can be used with anyListenable, includingChangeNotifier andValueNotifier.
AnimatedWidget is most useful for widgets that are otherwise stateless. TouseAnimatedWidget, subclass it and implement the build function.
Spinner that spins a green squarecontinually. It is built with anAnimatedWidget.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 usingAnimatedBuilder orListenableBuilder.
Relationship toImplicitlyAnimatedWidgets
AnimatedWidgets (and their subclasses) take an explicitListenable asargument, which is usually anAnimation derived from anAnimationController. In most cases, the lifecycle of thatAnimationController has to be managed manually by the developer.In contrast to that,ImplicitlyAnimatedWidgets (and their subclasses)automatically manage their own internalAnimationController making thoseclasses easier to use as no externalAnimation has to be provided by thedeveloper. If you only need to set a target value for the animation andconfigure 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 namedFooTransition, whereFoo is the name of the non-animatedversion of that widget. The subclasses of this class should not be confusedwith subclasses ofImplicitlyAnimatedWidget (see above), which are usuallynamedAnimatedFoo. Commonly used animated widgets include:
- ListenableBuilder, which uses a builder pattern that is useful forcomplexListenable use cases.
- AnimatedBuilder, which uses a builder pattern that is useful forcomplexAnimation use cases.
- AlignTransition, which is an animated version ofAlign.
- DecoratedBoxTransition, which is an animated version ofDecoratedBox.
- DefaultTextStyleTransition, which is an animated version ofDefaultTextStyle.
- PositionedTransition, which is an animated version ofPositioned.
- RelativePositionedTransition, which is an animated version ofPositioned.
- RotationTransition, which animates the rotation of a widget.
- ScaleTransition, which animates the scale of a widget.
- SizeTransition, which animates its own size.
- SlideTransition, which animates the position of a widget relative toits normal position.
- FadeTransition, which is an animated version ofOpacity.
- AnimatedModalBarrier, which is an animated version ofModalBarrier.
Constructors
- AnimatedWidget({Key?key,requiredListenablelistenable})
- 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
- TheListenable to which this widget is listening.final
- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
Methods
- build(
BuildContextcontext)→Widget - Override this method to build widgets that depend on the state of thelistenable (e.g., the current value of the animation).
- createElement(
)→StatefulElement - Creates aStatefulElement 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 ofDiagnosticsNode objects describing this node'schildren.inherited
- debugFillProperties(
DiagnosticPropertiesBuilderproperties)→ void - Add additional properties associated with the node.override
- noSuchMethod(
Invocationinvocation)→ 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 debuggingtools and byDiagnosticsNode.toStringDeep.inherited
- toString(
{DiagnosticLevelminLevel =DiagnosticLevel.info})→String - A string representation of this object.inherited
- toStringDeep(
{StringprefixLineOne ='',String?prefixOtherLines,DiagnosticLevelminLevel =DiagnosticLevel.debug,intwrapWidth =65})→String - Returns a string representation of this node and its descendants.inherited
- toStringShallow(
{Stringjoiner =', ',DiagnosticLevelminLevel =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 ==(
Objectother)→bool - The equality operator.inherited