Fix showBottomSheet
doesn't remove scrim when draggable sheet is dismissed (#128455)
fixes https://github.com/flutter/flutter/issues/128367 <details> <summary>code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(useMaterial3: true), home: Scaffold( floatingActionButton: Builder( builder: (BuildContext context) => FloatingActionButton( child: const Icon(Icons.add), onPressed: () { Scaffold.of(context).showBottomSheet<void>( (_) { return DraggableScrollableSheet( expand: false, builder: (_, ScrollController scrollController) => ListView.builder( controller: scrollController, itemCount: 25, itemBuilder: (BuildContext context, int index) { return ListTile( title: Text('Item $index - tap to close'), onTap: () { Navigator.of(context).pop(); }, ); }, ), ); }, ); }, ), ), ), ); } } ``` </details> ### Before https://github.com/flutter/flutter/assets/48603081/fa87feb9-54f2-4e50-bf71-c81d9e54ff61 ### After https://github.com/flutter/flutter/assets/48603081/7d192059-7600-4d65-ae84-6321f3598133
This commit is contained in:
parent
80b9ac2cfb
commit
8600eb129c
@ -2312,6 +2312,8 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
|
||||
|
||||
bottomSheetKey.currentState!.close();
|
||||
setState(() {
|
||||
_showBodyScrim = false;
|
||||
_bodyScrimColor = Colors.black.withOpacity(0.0);
|
||||
_currentBottomSheet = null;
|
||||
});
|
||||
|
||||
|
@ -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<ScaffoldState> scaffoldKey = GlobalKey();
|
||||
PersistentBottomSheetController<void>? sheetController;
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Scaffold(
|
||||
key: scaffoldKey,
|
||||
body: const Center(child: Text('body')),
|
||||
),
|
||||
));
|
||||
|
||||
sheetController = scaffoldKey.currentState!.showBottomSheet<void>((_) {
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user