Morph class
Animates a widget between two matching locations.
Give each appearance a stable MorphTarget with the same tag. Mounting a new appearance moves the shared visual to it; removing it returns to the most recently mounted appearance that remains. Rebuilds do not reorder appearances. A covered appearance cannot start a child-replacement flight.
Register a stable MorphNavigatorObserver from the creation of each Navigator containing Morphs. Local transitions also work in a standalone Overlay. Without an Overlay, child renders normally without transitions.
Eligible Widgets receive specialized transitions automatically. Other combinations move between their endpoint geometry and switch content halfway through. Configure flightConfig to change child replacement or supply a custom transition.
Generic transitions preserve inherited themes and MediaQuery values. They do not preserve other inherited values introduced locally around an endpoint. A live in-flight subtree must not contain GlobalKeys that are also mounted at an endpoint. Use MorphDescendant with MorphDescendantFlightBehavior.snapshot or MorphDescendantFlightBehavior.hide to keep such a subtree at its resting endpoint, or use a custom delegate when it must have a different in-flight visual.
When animateChildChanges is true, replacing child on the same Morph starts an in-place transition. Give the old and new children the same non-null key when a rebuild should update the resting widget without animating. Replacing an unkeyed child starts a transition whenever its widget instance changes.
When animations are disabled before a transition starts, Morph shows the destination immediately without invoking lifecycle callbacks. If they become disabled during a transition, Morph finishes immediately without invoking onReceived or onEnd; an earlier onStart remains invoked.
See the Morph guide for endpoint setup, automatic transitions, and customization.
- Inheritance
Constructors
- Morph({required MorphTarget target, required Widget child, MorphFlightConfig flightConfig = const MorphFlightConfig.auto(), Duration? duration, Curve? curve, bool watchDestination = false, bool animateChildChanges = false, VoidCallback? onStart, VoidCallback? onEnd, VoidCallback? onReceived, Key? key})
-
Creates an appearance that can transition to another with an equal tag.
const
Properties
- animateChildChanges → bool
-
Whether replacing child can start an in-place transition.
final
- child → Widget
-
Widget shown at this location when no transition is running.
final
- curve → Curve?
-
Curve applied while moving from the source to the destination.
final
- duration → Duration?
-
Duration of transitions started by this Morph.
final
- flightConfig → MorphFlightConfig
-
How the shared element appears during its transition.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onEnd → VoidCallback?
-
Called on the source after the transition reaches the destination.
final
- onReceived → VoidCallback?
-
Called on the destination immediately before the source's onEnd.
final
- onStart → VoidCallback?
-
Called on the source when its transition starts.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- target → MorphTarget
-
Identifier shared by the source, destination and sibling widgets.
final
- watchDestination → bool
-
Whether a flight departing from this Morph follows changes to its
destination's geometry and snapshotted descendants.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Morph> -
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, int wrapWidth = 65}) → 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