fling method Null safety

TickerFuture fling (
  1. {double velocity: 1.0,
  2. AnimationBehavior? animationBehavior}
)

Drives the animation with a critically damped spring (within lowerBound and upperBound) and initial velocity.

If velocity is positive, the animation will complete, otherwise it will dismiss.

Returns a TickerFuture that completes when the animation is complete.

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 fling({ double velocity = 1.0, AnimationBehavior? animationBehavior }) {
  _direction = velocity < 0.0 ? _AnimationDirection.reverse : _AnimationDirection.forward;
  final double target = velocity < 0.0 ? lowerBound - _kFlingTolerance.distance
                                       : upperBound + _kFlingTolerance.distance;
  double scale = 1.0;
  final AnimationBehavior behavior = animationBehavior ?? this.animationBehavior;
  if (SemanticsBinding.instance!.disableAnimations) {
    switch (behavior) {
      case AnimationBehavior.normal:
        // TODO(jonahwilliams): determine a better process for setting velocity.
        // the value below was arbitrarily chosen because it worked for the drawer widget.
        scale = 200.0;
        break;
      case AnimationBehavior.preserve:
        break;
    }
  }
  final Simulation simulation = SpringSimulation(_kFlingSpringDescription, value, target, velocity * scale)
    ..tolerance = _kFlingTolerance;
  stop();
  return _startSimulation(simulation);
}