fling method

TickerFuture fling(
  1. {double velocity = 1.0,
  2. SpringDescription? springDescription,
  3. AnimationBehavior? animationBehavior}

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

If velocity is positive, the animation will complete, otherwise it will dismiss. The velocity is specified in units per second. If the SemanticsBinding.disableAnimations flag is set, the velocity is somewhat arbitrarily multiplied by 200.

The springDescription parameter can be used to specify a custom SpringType.criticallyDamped or SpringType.overDamped spring with which to drive the animation. By default, a SpringType.criticallyDamped spring is used. See SpringDescription.withDampingRatio for how to create a suitable SpringDescription.

The resulting spring simulation cannot be of type SpringType.underDamped; such a spring would oscillate rather than fling.

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.


TickerFuture fling({ double velocity = 1.0, SpringDescription? springDescription, AnimationBehavior? animationBehavior }) {
  springDescription ??= _kFlingSpringDescription;
  _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:
        scale = 200.0; // This is arbitrary (it was chosen because it worked for the drawer widget).
      case AnimationBehavior.preserve:
  final SpringSimulation simulation = SpringSimulation(springDescription, value, target, velocity * scale)
    ..tolerance = _kFlingTolerance;
    simulation.type != SpringType.underDamped,
    'The specified spring simulation is of type SpringType.underDamped.\n'
    'An underdamped spring results in oscillation rather than a fling. '
    'Consider specifying a different springDescription, or use animateWith() '
    'with an explicit SpringSimulation if an underdamped spring is intentional.',
  return _startSimulation(simulation);