diff --git a/packages/flutter/lib/src/widgets/scroll_position.dart b/packages/flutter/lib/src/widgets/scroll_position.dart index 2585985450..dd5d9596b9 100644 --- a/packages/flutter/lib/src/widgets/scroll_position.dart +++ b/packages/flutter/lib/src/widgets/scroll_position.dart @@ -750,7 +750,7 @@ class DrivenScrollActivity extends ScrollActivity { } void _end() { - position.beginBallisticActivity(velocity); + position?.beginBallisticActivity(velocity); } @override diff --git a/packages/flutter/test/widgets/scroll_controller_test.dart b/packages/flutter/test/widgets/scroll_controller_test.dart index ee09fddbc8..f3e872a387 100644 --- a/packages/flutter/test/widgets/scroll_controller_test.dart +++ b/packages/flutter/test/widgets/scroll_controller_test.dart @@ -143,4 +143,21 @@ void main() { expect(controller.offset, equals(105.0)); expect(realOffset(), equals(controller.offset)); }); + + testWidgets('DrivenScrollActivity ending after dispose', (WidgetTester tester) async { + ScrollController controller = new ScrollController(); + + await tester.pumpWidget(new ListView( + controller: controller, + children: [ new Container(height: 200000.0) ], + )); + + controller.animateTo(1000.0, duration: const Duration(seconds: 1), curve: Curves.linear); + + await tester.pump(); // Start the animation. + + // We will now change the tree on the same frame as the animation ends. + await tester.pumpWidget(new Container(), const Duration(seconds: 2)); + }); + }