diff --git a/packages/flutter/lib/src/widgets/scroll_position.dart b/packages/flutter/lib/src/widgets/scroll_position.dart index 706bb23ba1..2c43ef43ad 100644 --- a/packages/flutter/lib/src/widgets/scroll_position.dart +++ b/packages/flutter/lib/src/widgets/scroll_position.dart @@ -629,8 +629,11 @@ class DragScrollActivity extends ScrollActivity { @override Notification createScrollEndNotification(AbstractScrollState scrollable) { - assert(_lastDetails is DragEndDetails); - return new ScrollEndNotification(scrollable: scrollable, dragDetails: _lastDetails); + // We might not have DragEndDetails yet if we're being called from beginActivity. + return new ScrollEndNotification( + scrollable: scrollable, + dragDetails: _lastDetails is DragEndDetails ? _lastDetails : null + ); } @override diff --git a/packages/flutter/test/widgets/scroll_view_test.dart b/packages/flutter/test/widgets/scroll_view_test.dart index c27c759e3c..c44b90de71 100644 --- a/packages/flutter/test/widgets/scroll_view_test.dart +++ b/packages/flutter/test/widgets/scroll_view_test.dart @@ -115,4 +115,57 @@ void main() { expect(log, equals(['Massachusetts'])); log.clear(); }); + + testWidgets('Can jumpTo during drag', (WidgetTester tester) async { + final List log = []; + final ScrollController controller = new ScrollController(); + + await tester.pumpWidget(new NotificationListener( + onNotification: (ScrollNotification notification) { + log.add(notification.runtimeType); + return false; + }, + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container( + height: 200.0, + child: new Text(state), + ); + }).toList(), + ), + )); + + expect(log, isEmpty); + + TestGesture gesture = await tester.startGesture(const Point(100.0, 100.0)); + await gesture.moveBy(const Offset(0.0, -100.0)); + + expect(log, equals([ + ScrollStartNotification, + UserScrollNotification, + ScrollUpdateNotification, + ])); + log.clear(); + + await tester.pump(); + + controller.jumpTo(550.0); + + expect(controller.offset, equals(550.0)); + expect(log, equals([ + ScrollEndNotification, + UserScrollNotification, + ScrollStartNotification, + ScrollUpdateNotification, + ScrollEndNotification, + ])); + log.clear(); + + await tester.pump(); + await gesture.moveBy(const Offset(0.0, -100.0)); + + expect(controller.offset, equals(550.0)); + expect(log, isEmpty); + }); }