toggle method

TickerFuture toggle({
  1. double? from,
})

Toggles the direction of this animation, based on whether it isForwardOrCompleted.

Specifically, this function acts the same way as reverse if the status is either AnimationStatus.forward or AnimationStatus.completed, and acts as forward for AnimationStatus.reverse or AnimationStatus.dismissed.

If from is non-null, it will be set as the current value before running the animation.

The most recently returned TickerFuture, if any, is marked as having been canceled, meaning the future never completes and its TickerFuture.orCancel derivative future completes with a TickerCanceled error.

Implementation

TickerFuture toggle({ double? from }) {
  assert(() {
    Duration? duration = this.duration;
    if (isForwardOrCompleted) {
      duration ??= reverseDuration;
    }
    if (duration == null) {
      throw FlutterError(
        'AnimationController.toggle() called with no default duration.\n'
        'The "duration" property should be set, either in the constructor or later, before '
        'calling the toggle() function.',
      );
    }
    return true;
  }());
  assert(
    _ticker != null,
    'AnimationController.toggle() called after AnimationController.dispose()\n'
    'AnimationController methods should not be used after calling dispose.',
  );
  _direction = isForwardOrCompleted ? _AnimationDirection.reverse : _AnimationDirection.forward;
  if (from != null) {
    value = from;
  }
  return _animateToInternal(switch (_direction) {
    _AnimationDirection.forward => upperBound,
    _AnimationDirection.reverse => lowerBound,
  });
}