diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index 9f0cf6659a..d2bfceb407 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -508,7 +508,7 @@ class _ModalBottomSheetRoute extends PopupRoute { _animationController = transitionAnimationController; willDisposeAnimationController = false; } else { - _animationController = BottomSheet.createAnimationController(navigator!.overlay!); + _animationController = BottomSheet.createAnimationController(navigator!); } return _animationController!; } diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index e3a569f771..94fb1812c3 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -51,6 +51,43 @@ void main() { FlutterError.onError = handler; }); + testWidgets('Disposing app while bottom sheet is disappearing does not crash', (WidgetTester tester) async { + late BuildContext savedContext; + + await tester.pumpWidget( + MaterialApp( + home: Builder( + builder: (BuildContext context) { + savedContext = context; + return Container(); + }, + ), + ), + ); + + await tester.pump(); + expect(find.text('BottomSheet'), findsNothing); + + // Bring up bottom sheet. + bool showBottomSheetThenCalled = false; + showModalBottomSheet( + context: savedContext, + builder: (BuildContext context) => const Text('BottomSheet'), + ).then((void value) { + showBottomSheetThenCalled = true; + }); + await tester.pumpAndSettle(); + expect(find.text('BottomSheet'), findsOneWidget); + expect(showBottomSheetThenCalled, isFalse); + + // Start closing animation of Bottom sheet. + tester.state(find.byType(Navigator)).pop(); + await tester.pump(); + + // Dispose app by replacing it with a container. This shouldn't crash. + await tester.pumpWidget(Container()); + }); + testWidgets('Tapping on a modal BottomSheet should not dismiss it', (WidgetTester tester) async { late BuildContext savedContext;