fling method Null safety
- {double velocity = 1.0,
- SpringDescription? springDescription,
- 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 springDescription
parameter can be used to specify a custom SpringType.criticallyDamped
or SpringType.overDamped spring to drive the animation with. Defaults to null, which uses a
SpringType.criticallyDamped spring. See SpringDescription.withDampingRatio for how
to create a suitable SpringDescription.
The resulting spring simulation cannot be of type SpringType.underDamped, as this can lead to unexpected look of the produced animation.
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, 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:
// TODO(zanderso): 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 SpringSimulation simulation = SpringSimulation(springDescription, value, target, velocity * scale)
..tolerance = _kFlingTolerance;
assert(
simulation.type != SpringType.underDamped,
'The resulting spring simulation is of type SpringType.underDamped.\n'
'This can lead to unexpected look of the animation, please adjust the springDescription parameter',
);
stop();
return _startSimulation(simulation);
}