From 0736fac441b6bd621d146bec717d1690a30440ce Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 16 Feb 2017 17:15:03 -0800 Subject: [PATCH] DrivenScrollActivity._end didn't handle being already disposed (#8219) --- .../lib/src/widgets/scroll_position.dart | 2 +- .../test/widgets/scroll_controller_test.dart | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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)); + }); + }