From a78ad92d1e8d3d4a347d8a2a2e5ac7c39f3802cc Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Wed, 14 Sep 2016 15:50:30 -0700 Subject: [PATCH] Small revision to ScrollableState.fling() (#5871) --- packages/flutter/lib/src/widgets/scrollable.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index 038652c885..9c865b8c95 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -511,14 +511,24 @@ class ScrollableState extends State { updateGestureDetector(); } - /// Fling the scroll offset with the given velocity in logical pixels/second. + /// If [scrollVelocity] is greater than [PixelScrollTolerance.velocity] then + /// fling the scroll offset with the given velocity in logical pixels/second. + /// Otherwise, if this scrollable is overscrolled or a [snapOffsetCallback] + /// was given, animate the scroll offset to its final value with [settleScrollOffset]. /// /// Calling this function starts a physics-based animation of the scroll /// offset with the given value as the initial velocity. The physics /// simulation is determined by the scroll behavior. Future fling(double scrollVelocity) { - if (scrollVelocity.abs() > kPixelScrollTolerance.velocity || !_controller.isAnimating) + if (scrollVelocity.abs() > kPixelScrollTolerance.velocity) return _startToEndAnimation(scrollVelocity); + + // If a scroll animation isn't underway already and we're overscrolled or we're + // going to have to snap the scroll offset, then animate the scroll offset to its + // final value. + if (!_controller.isAnimating && (shouldSnapScrollOffset || !_scrollOffsetIsInBounds(scrollOffset))) + return settleScrollOffset(); + return new Future.value(); }