Repository navigation
ModalBottomSheet with isScrollControlled doesn't respect SafeArea #39205
Copy link
Copy link
Labels
a: layoutSystemChrome and Framework's Layout IssuesSystemChrome and Framework's Layout Issuesfound in release: 1.20Found to occur in 1.20Found to occur in 1.20frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Steps to Reproduce
- Create a modal bottom sheet with Scaffold as its child
- Wrap the Scaffold into a SafeArea widget
- Add a Text widget in Scaffold's body
- Run the application on a device with notch
- Open the modal bottom sheet and notice that the text is under the status bar
Code example
import 'package:flutter/material.dart';
class ModalBottomSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(),
floatingActionButton: FloatingActionButton(
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.black45,
body: Text(
'Text in safe area',
style: TextStyle(backgroundColor: Colors.red),
),
),
);
});
},
child: Icon(Icons.add),
),
);
}
}
Screenshots
Logs
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.6 18G87, locale en-US)
• Flutter version 1.7.8+hotfix.4 at /Users/user/flutter
• Framework revision 20e59316b8 (5 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/user/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.3, Build version 10G8
• CocoaPods version 1.7.5
[✗] iOS tools - develop for iOS devices
✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install:
brew install ios-deploy
! Brew can be used to install tools for iOS device development.
Download brew at https://brew.sh/.
[✓] Android Studio (version 3.4)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 37.0.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[✓] VS Code (version 1.37.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.3.0
[✓] Connected device (2 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• iPhone Xs Max • 9C9C7B29-18A5-4D3A-8F53-CE6EB58C5411 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
! Doctor found issues in 1 category.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: layoutSystemChrome and Framework's Layout IssuesSystemChrome and Framework's Layout Issuesfound in release: 1.20Found to occur in 1.20Found to occur in 1.20frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Type
Projects
- StatusShow more project fieldsDone (PR merged)

Activity
macoshita commentedon Oct 18, 2019
In bottom_sheet.dart, use
MediaQuery.removePadding(removeTop: true).For that reason, builder's context no have paddingTop, so ModalBottomSheet doesn't respect SafeArea.
Fix it if I change the code this:
But... I am not familiar with ModalBottomSheet's use case. I don't know if this can handle various cases.
antondokusov commentedon Nov 26, 2019
Workaround:
legalcodes commentedon Dec 11, 2019
Has anyone tried to replicate this issue with persistent bottom sheet? Seeing this on stable Flutter 1.91. @workerbee22
layou1989 commentedon Mar 15, 2020
has any solution??
walidbagh commentedon Apr 24, 2020
Any news on this issue ?
Those guys have pinpointed the source of the issue and fixed it ...
jonataslaw/getx#44
cuong1112035 commentedon Apr 25, 2020
any update?, I have the same issue.
MediaQuery.of(context).padding.topreturns 0 in this caseDKMonster commentedon May 7, 2020
@cuong1112035 I had same issue, and I find the reason. the context is showModalSheet context. you can try to get the main context like this code:
Main dart file
and using the
mainContextto setMediaQuery.of(widget.context).padding.top.CalendarAddWidget dart file
That's solve my problem. :D
TahaTesser commentedon Jul 1, 2020
Code Sample
flutter doctor -v
5 remaining items
marianhlavac commentedon Jan 30, 2021
Still not fixed, currently not able to create persistent bottom sheet, with correctly working SafeArea inside.
Scaffold.of(context).showBottomSheet(...is broken and SafeArea doesn't work in itshowModalBottomSheet(...works as expected and allows SafeArea to be used insideIs anyone looking into this?
rajivrajan commentedon Feb 1, 2021
A much simpler approach, just take the Window Object from WidgetBinding instance, and use
MediaQueryData.fromWindow(WidgetsBinding.instance.window).padding.top;this gives you the padding required, now just place whatever widget you want in a container, with the margin :)
welfvh commentedon Feb 23, 2021
How is this 18 months old and still not fixed?
uc-dve commentedon Apr 23, 2021
It will be fixed or not, wasting time due to searching solution but there is no solution and still using work-around.
kyawthet-naing commentedon May 24, 2021
That is my code->

showModalBottomSheet(
backgroundColor: Colors.transparent,
isScrollControlled: true,
context: context,
builder: (_) => Padding(
padding:
EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: Container(color: Colors.indigo, child: Column()),
));
steven-spiel commentedon May 28, 2021
You may not actually need a scrollable bottom sheet if you want it to take up the whole screen.
Depending on your use case, this might do the trick: Ineractive Example
N00nDay commentedon Aug 26, 2021
I can at least find work around for content in the body. I have found 0 work arounds for the appBar.
github-actions commentedon Aug 4, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.