ListenEffect class
An effect that calls a callback function with its current animation value between begin and end.
By default, the callback will only be called while this effect is "active"
(ie. after delay, and before duration) and will return a value between 0-1
(unless the curve transforms it beyond this range). If clamp is set to false
,
the callback will be called on every tick while the enclosing Animate is
running, and may return values outside its nominal range (ex. it will return a
negative value before delay).
This example will print the current animation value (which matches the value of the preceding fade effect's opacity value):
Text("Hello").animate().fadeIn(curve: Curves.easeOutExpo)
.listen(callback: (value) => print('current opacity: $value'))
This can easily be used to drive a ValueNotifier:
ValueNotifier<double> notifier = ValueNotifier<double>(0);
Text("Hello").animate()
.fadeIn(delay: 400.ms, duration: 900.ms)
.listen(callback: (value) => notifier.value)
See also: CustomEffect and CallbackEffect.
Constructors
-
ListenEffect({Duration? delay, Duration? duration, Curve? curve, double? begin, double? end, required ValueChanged<
double> callback, bool clamp = true}) -
const
Properties
- begin → double?
-
The begin value for the effect. If null, effects should use a reasonable
default value when appropriate.
finalinherited
-
callback
→ ValueChanged<
double> -
final
- clamp → bool
-
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 → double?
-
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< double> -
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
toggle
function 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