@@ -645,18 +645,27 @@ class AnimationController extends Animation<double>
645645 _checkStatusChanged ();
646646 }
647647
648- /// Drives the animation with a critically damped spring (within [lowerBound]
649- /// and [upperBound] ) and initial velocity.
648+ /// Drives the animation with a spring (within [lowerBound] and [upperBound] )
649+ /// and initial velocity.
650650 ///
651651 /// If velocity is positive, the animation will complete, otherwise it will
652652 /// dismiss.
653653 ///
654+ /// The [springDescription] parameter can be used to specify a custom [SpringType.criticallyDamped]
655+ /// or [SpringType.overDamped] spring to drive the animation with. Defaults to null, which uses a
656+ /// [SpringType.criticallyDamped] spring. See [SpringDescription.withDampingRatio] for how
657+ /// to create a suitable [SpringDescription] .
658+ ///
659+ /// The resulting spring simulation cannot be of type [SpringType.underDamped] ,
660+ /// as this can lead to unexpected look of the produced animation.
661+ ///
654662 /// Returns a [TickerFuture] that completes when the animation is complete.
655663 ///
656664 /// The most recently returned [TickerFuture] , if any, is marked as having been
657665 /// canceled, meaning the future never completes and its [TickerFuture.orCancel]
658666 /// derivative future completes with a [TickerCanceled] error.
659- TickerFuture fling ({ double velocity = 1.0 , AnimationBehavior ? animationBehavior }) {
667+ TickerFuture fling ({ double velocity = 1.0 , SpringDescription ? springDescription, AnimationBehavior ? animationBehavior }) {
668+ springDescription ?? = _kFlingSpringDescription;
660669 _direction = velocity < 0.0 ? _AnimationDirection .reverse : _AnimationDirection .forward;
661670 final double target = velocity < 0.0 ? lowerBound - _kFlingTolerance.distance
662671 : upperBound + _kFlingTolerance.distance;
@@ -673,8 +682,13 @@ class AnimationController extends Animation<double>
673682 break ;
674683 }
675684 }
676- final Simulation simulation = SpringSimulation (_kFlingSpringDescription , value, target, velocity * scale)
685+ final SpringSimulation simulation = SpringSimulation (springDescription , value, target, velocity * scale)
677686 ..tolerance = _kFlingTolerance;
687+ assert (
688+ simulation.type != SpringType .underDamped,
689+ 'The resulting spring simulation is of type SpringType.underDamped.\n '
690+ 'This can lead to unexpected look of the animation, please adjust the springDescription parameter'
691+ );
678692 stop ();
679693 return _startSimulation (simulation);
680694 }
0 commit comments