SwapEffect class
An effect that swaps out the incoming child for a new child at a particular point in time. This includes all preceding effects. It uses a builder so that the effect can be reused, but note that the builder is only called once when the effect initially builds.
For example, this would fade out foo, swap it for Bar() (including
discarding the fadeOut effect) and apply a fade in effect.
foo.animate()
.fadeOut(duration: 500.ms)
.swap( // inherits duration from fadeOut
builder: (_, __) => Bar().animate().fadeIn(),
)
It also includes the original child of the animation as a parameter of the builder. For example, normally fading out and then back in will not work as expected because both effects are active (ie. the 0 opacity from fading out is still applied), but you can work around this by beginning a new animation with the original child:
foo.animate()
.fadeOut(duration: 500.ms)
.swap( // inherits duration from fadeOut
builder: (_, originalChild) => originalChild.animate().fadeIn(),
)
Note that the builder is returning a new Animate instance with its own AnimationController. So, for example, repeating the first animation (the fade out) via its controller will not affect the second animation (fade in).
Constructors
- SwapEffect({Duration? delay, Duration? duration, Curve? curve, required Widget builder(BuildContext, Widget)})
-
const
Properties
- begin → void
-
The begin value for the effect. If null, effects should use a reasonable
default value when appropriate.
finalinherited
- builder → Widget Function(BuildContext, Widget)
-
final
- curve → Curve?
-
The specified easing curve for the effect. If null, will inherit the curve from the
previous effect, or use Animate.defaultCurve if this is the first effect.
finalinherited
- delay → Duration?
-
The specified delay for the effect. If null, will inherit the delay from the
previous effect, or use Duration.zero if this is the first effect.
finalinherited
- duration → Duration?
-
The specified duration for the effect. If null, will inherit the duration from the
previous effect, or use Animate.defaultDuration if this is the first effect.
finalinherited
- end → void
-
The end value for the effect. If null, effects should use a reasonable
default value when appropriate.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
BuildContext context, Widget child, AnimationController controller, EffectEntry entry) → Widget -
Builds the widgets that implement the effect on the target
child, based on the provided AnimationController and EffectEntry.override -
buildAnimation(
AnimationController controller, EffectEntry entry) → Animation< void> -
Returns an animation based on the controller, entry, and begin/end values.
inherited
-
getBeginRatio(
AnimationController controller, EffectEntry entry) → double -
Returns a ratio corresponding to the beginning of the specified entry.
inherited
-
getEndRatio(
AnimationController controller, EffectEntry entry) → double -
Returns a ratio corresponding to the end of the specified entry.
inherited
-
getOptimizedBuilder<
U> ({required ValueListenable< U> animation, Widget? child, required TransitionBuilder builder}) → AnimatedBuilder -
Returns an optimized AnimatedBuilder that doesn't
rebuild if the value hasn't changed.
inherited
-
getToggleBuilder(
{required ValueListenable< double> animation, required Widget child, required bool toggle(), required ToggleEffectBuilder builder}) → AnimatedBuilder -
Returns an AnimatedBuilder that rebuilds when the
boolean value returned by the
togglefunction changes.inherited -
isAnimationActive(
Animation animation) → bool -
Check if the animation is currently running / active.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited