Skip to content

[material_ui] showModalBottomSheet(useSafeArea: true) subtracts the opposite safe area from a sheet on a display-feature sub-screen #195218

Closed
flutter/packages
#13428

Description

@4KDV

Steps to reproduce

  1. Use a window with a hinge DisplayFeature and a side safe area, e.g. a foldable held as a book with the status bar on the right (iPhone Duo simulator, Xcode 27.1, iOS 27.1, inner display 951 × 669 pt).
  2. Call showModalBottomSheet(useSafeArea: true, anchorPoint: …) with an anchor on the left sub-screen.
  3. Run the test below.

Expected results

The sheet fills the left sub-screen: 455.5 pt wide. That sub-screen does not touch the right safe area, so nothing should be subtracted.

Actual results

The sheet is 375.5 pt wide. The right inset (80 pt) of the window is subtracted from the left sub-screen as well. With useSafeArea: false the width is 455.5 pt.

In the iPhone Duo simulator (Xcode 27.1 Device Hub, book posture, status bar on the right), a left sheet is about 372 pt wide instead of 455 pt. A dimmed strip is left between the sheet and the hinge.

Cause

ModalBottomSheetRoute.buildPage wraps the DisplayFeatureSubScreen in the SafeArea:

final Widget content = DisplayFeatureSubScreen(anchorPoint: anchorPoint, child: …);
Widget bottomSheet = useSafeArea
    ? SafeArea(bottom: false, child: content)
    : MediaQuery.removePadding(context: context, removeTop: true, child: content);

SafeArea shrinks the constraints but keeps MediaQuery.size. DisplayFeatureSubScreen therefore pads to the sub-screen in full-window coordinates (right: parentSize.width - subScreen.right) inside a box that is already narrower by the inset.

RawDialogRoute (showDialog) applies its SafeArea inside DisplayFeatureSubScreen. There, MediaQueryData.removeDisplayFeatures already gives each sub-screen only the padding of its own edges. Putting the sheet's SafeArea inside the sub-screen in the same way would fix this.

Code sample

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('a sheet on the left sub-screen keeps its width', (tester) async {
    tester.view.devicePixelRatio = 1;
    tester.view.physicalSize = const Size(951, 669);
    tester.view.padding = const FakeViewPadding(right: 80);
    addTearDown(tester.view.reset);
    await tester.pumpWidget(
      MaterialApp(
        builder: (context, child) => MediaQuery(
          data: MediaQuery.of(context).copyWith(
            displayFeatures: const <DisplayFeature>[
              DisplayFeature(
                bounds: Rect.fromLTWH(455.5, 0, 40, 669),
                type: DisplayFeatureType.hinge,
                state: DisplayFeatureState.postureHalfOpened,
              ),
            ],
          ),
          child: child!,
        ),
        home: Builder(
          builder: (context) => Scaffold(
            body: Align(
              alignment: Alignment.topLeft,
              child: ElevatedButton(
                onPressed: () => showModalBottomSheet<void>(
                  context: context,
                  useSafeArea: true,
                  anchorPoint: const Offset(100, 669),
                  builder: (_) =>
                      const SizedBox(height: 200, child: Placeholder()),
                ),
                child: const Text('open'),
              ),
            ),
          ),
        ),
      ),
    );
    await tester.tap(find.text('open'));
    await tester.pumpAndSettle();
    // Fails: actual width is 375.5.
    expect(tester.getSize(find.byType(Placeholder)).width, 455.5);
  });
}

The same happens vertically. In a 669 × 951 window with a 24 pt top inset and a horizontal hinge at y 455.5 (tabletop), a tall isScrollControlled sheet on the lower sub-screen starts at y 519.5 instead of 495.5. It loses the top inset that belongs to the other sub-screen.

Flutter version

Flutter 3.47.7 • channel stable • https://github.com/flutter/flutter.git
Framework • revision abaf9c5237 • 2026-10-08 09:51:21 -0700
Engine • hash d8a2d6c768c334d53e16277f837970ffa1e2de81 (revision deb287481e)
Tools • Dart 3.13.5 • DevTools 2.60.0

The widget test fails on macOS. Device check: iPhone Duo simulator, iOS 27.1. The wrapping is unchanged on master.

Related, but not the same: #121554 (gap below the sheet with useSafeArea), #175379 (extra side margin in landscape on Android), #192667 (MediaQuery.sizeOf inside a sub-screen reports the whole window).

Activity

  1. added
    in triage
    on Oct 26, 2026
  2. saurabh-mirajkar commented on Oct 26, 2026

    @saurabh-mirajkar
    Contributor

    @4KDV Thanks for the detailed report. I reproduced this on Flutter 3.47.8 stable. Routing this to the design team for evaluation.

  3. added
    p: material_ui
    package
    a: layout
    has reproducible steps
    a: adaptivity
    team-design
    and removed
    in triage
    on Oct 26, 2026
  4. changed the title [-]`showModalBottomSheet(useSafeArea: true)` subtracts the opposite safe area from a sheet on a display-feature sub-screen[/-] [+][material_ui] `showModalBottomSheet(useSafeArea: true)` subtracts the opposite safe area from a sheet on a display-feature sub-screen[/+] on Oct 27, 2026
  5. added
    P2
    triaged-design
    on Oct 27, 2026
  6. added a commit that references this issue on Nov 23, 2026
    93abddf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: adaptivitya: layouthas reproducible stepsp: material_uipackageteam-designtriaged-design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions