I am using MaterialApp and Scaffold + SafeArea for screens. All works well until I try to use persistent BottomSheet. BottomSheet content igores SafeArea and are shown below system controls, for example in iPhone X.
I tried to wrap BottomSheet contents in another SafeArea element, but it did not help.
Is there a way to get the same functionality as SafeArea to work in BottomSheet? If yes then how?
SafeArea class Null safety. A widget that insets its child by sufficient padding to avoid intrusions by the operating system. For example, this will indent the child by enough to avoid the status bar at the top of the screen.
It is true by default and setting it to false would disable SafeArea from adding padding to the bottom of the screen. top : This property is also of type bool and setting it to false would avoid padding at top of the screen.
If you're developing an application using Flutter, avoiding content being clipped by system intrusions can be done by using SafeArea widget. You can set on which sides the system intrusions should be avoided and also the minimum padding to be applied on each side.
It's possible this way: showModalBottomSheet( context: context, isScrollControlled: true, backgroundColor: Colors. transparent, builder: (context) => Container( height: MediaQuery. of(context).
Just make the root Widget of the showModalBottomSheet be a SafeArea Widget
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[...
I have faced this issue too. When I changed code from showModalBottomSheet
to _scaffoldKey.currentState.showBottomSheet
my SafeArea
stopped working.
You can solve it with these steps:
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
key: _scaffoldKey,
padding: EdgeInsets.only(bottom: MediaQuery.of(_scaffoldKey.currentState.context).viewPadding.bottom)
Here is a result, I also added 15 padding to top, left and right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With