animateTo method
Triggers an animation, and returns a TickerFuture that completes when it finishes.
// using the .animateTo() method
_animation.animateTo(
target: newValue,
duration: Durations.medium1,
curve: Curves.ease,
);
// equivalent to:
_animation
..duration = Durations.medium1
..curve = Curves.ease
..value = newValue;
Implementation
@override
TickerFuture animateTo(T target, {T? from, Duration? duration, Curve? curve}) {
assert(_ticker != null, 'Cannot animate after the ValueAnimation was disposed of.');
_ticker!.stop(canceled: true);
if (duration != null) {
this.duration = duration;
}
if (curve != null) {
this.curve = curve;
}
if (from == null && value == target) {
return TickerFuture.complete();
}
if (this.duration == Duration.zero || !animationBehavior.enableAnimations) {
value = target;
_statusUpdate(AnimationStatus.completed);
return TickerFuture.complete();
}
_from = from ?? value;
_target = target;
_value = lerp(_from, _target, 0) as T;
_statusUpdate(AnimationStatus.forward);
return _ticker!.start();
}