diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index d9d239c529..7d40251848 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -2312,6 +2312,8 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto bottomSheetKey.currentState!.close(); setState(() { + _showBodyScrim = false; + _bodyScrimColor = Colors.black.withOpacity(0.0); _currentBottomSheet = null; }); diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index f4dd934ec5..acba212853 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -2754,6 +2754,52 @@ void main() { expect(tester.takeException(), isNull); }); + + testWidgets('showBottomSheet removes scrim when draggable sheet is dismissed', (WidgetTester tester) async { + final DraggableScrollableController draggableController = DraggableScrollableController(); + final GlobalKey scaffoldKey = GlobalKey(); + PersistentBottomSheetController? sheetController; + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + key: scaffoldKey, + body: const Center(child: Text('body')), + ), + )); + + sheetController = scaffoldKey.currentState!.showBottomSheet((_) { + return DraggableScrollableSheet( + expand: false, + controller: draggableController, + builder: (BuildContext context, ScrollController scrollController) { + return SingleChildScrollView( + controller: scrollController, + child: const Placeholder(), + ); + }, + ); + }); + + Finder findModalBarrier() => find.descendant(of: find.byType(Scaffold), matching: find.byType(ModalBarrier)); + + await tester.pump(); + expect(find.byType(BottomSheet), findsOneWidget); + + // The scrim is not present yet. + expect(findModalBarrier(), findsNothing); + + // Expand the sheet to 80% of parent height to show the scrim. + draggableController.jumpTo(0.8); + await tester.pump(); + expect(findModalBarrier(), findsOneWidget); + + // Dismiss the sheet. + sheetController.close(); + await tester.pumpAndSettle(); + + // The scrim should be gone. + expect(findModalBarrier(), findsNothing); + }); } class _GeometryListener extends StatefulWidget {