Skip to content

Commit 23b7bbd

Browse files
authored
ModalBottomSheetRoute: Remove gap at screen bottom with useSafeArea: true (#122118)
ModalBottomSheetRoute: Remove gap at screen bottom with `useSafeArea: true`
1 parent 0cf593e commit 23b7bbd

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

packages/flutter/lib/src/material/bottom_sheet.dart

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,10 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
624624
/// The [enableDrag] parameter specifies whether the bottom sheet can be
625625
/// dragged up and down and dismissed by swiping downwards.
626626
///
627-
/// The [useSafeArea] parameter specifies whether a [SafeArea] is inserted. Defaults to false.
628-
/// If false, no SafeArea is added and the top padding is consumed using [MediaQuery.removePadding].
627+
/// The [useSafeArea] parameter specifies whether the sheet will avoid system
628+
/// intrusions on the top, left, and right. If false, no SafeArea is added
629+
/// and the top padding is consumed using [MediaQuery.removePadding].
630+
/// Defaults to false.
629631
///
630632
/// The optional [backgroundColor], [elevation], [shape], [clipBehavior],
631633
/// [constraints] and [transitionAnimationController]
@@ -783,12 +785,18 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
783785
/// {@macro flutter.widgets.DisplayFeatureSubScreen.anchorPoint}
784786
final Offset? anchorPoint;
785787

786-
/// If useSafeArea is true, a [SafeArea] is inserted.
788+
/// Whether to avoid system intrusions on the top, left, and right.
787789
///
788-
/// If useSafeArea is false, the bottom sheet is aligned to the bottom of the page
789-
/// and isn't exposed to the top padding of the MediaQuery.
790+
/// If true, a [SafeArea] is inserted to keep the bottom sheet away from
791+
/// system intrusions at the top, left, and right sides of the screen.
790792
///
791-
/// Default is false.
793+
/// If false, the bottom sheet isn't exposed to the top padding of the
794+
/// MediaQuery.
795+
///
796+
/// In either case, the bottom sheet extends all the way to the bottom of
797+
/// the screen, including any system intrusions.
798+
///
799+
/// The default is false.
792800
final bool useSafeArea;
793801

794802
/// {@template flutter.material.ModalBottomSheetRoute.barrierOnTapHint}
@@ -871,11 +879,8 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
871879
),
872880
);
873881

874-
// If useSafeArea is true, a SafeArea is inserted.
875-
// If useSafeArea is false, the bottom sheet is aligned to the bottom of the page
876-
// and isn't exposed to the top padding of the MediaQuery.
877882
final Widget bottomSheet = useSafeArea
878-
? SafeArea(child: content)
883+
? SafeArea(bottom: false, child: content)
879884
: MediaQuery.removePadding(
880885
context: context,
881886
removeTop: true,

packages/flutter/test/material/bottom_sheet_test.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,18 @@ void main() {
762762
await tester.pump();
763763
await tester.pump(const Duration(seconds: 1));
764764

765-
// Top padding is consumed and there is a SafeArea
766-
expect(MediaQuery.of(innerContext).padding.top, 0);
767-
expect(find.byType(SafeArea), findsOneWidget);
765+
// A SafeArea is inserted, with left / top / right true but bottom false.
766+
final Finder safeAreaWidgetFinder = find.byType(SafeArea);
767+
expect(safeAreaWidgetFinder, findsOneWidget);
768+
final SafeArea safeAreaWidget = safeAreaWidgetFinder.evaluate().single.widget as SafeArea;
769+
expect(safeAreaWidget.left, true);
770+
expect(safeAreaWidget.top, true);
771+
expect(safeAreaWidget.right, true);
772+
expect(safeAreaWidget.bottom, false);
773+
774+
// Because that SafeArea is inserted, no left / top / right padding remains
775+
// for `builder` to consume. Bottom padding does remain.
776+
expect(MediaQuery.of(innerContext).padding, const EdgeInsets.fromLTRB(0, 0, 0, 50.0));
768777
});
769778

770779
testWidgets('modal BottomSheet has semantics', (WidgetTester tester) async {

0 commit comments

Comments
 (0)