You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Modal bottom sheets should not dismiss on tapping the sheet body #20720
Currently showModalBottomSheet() allows dismissing the displayed sheet by tapping on its body.
The modal bottom sheet should not dismiss upon tapping the general body.
I'm troubling with the problem too, I wonder how you use the GestureDetector to solve the dismissing of bottom sheet when tapping its body? Could you please show me a simple code example?
Have already solved, thanks a lot!
Reacted by Kyaw Tun, Leo, József Barát, Mateus Gustavo de Freitas e Silva, Herohtar, LiuYanQi, Amyrotos, George Chailazopoulos, RommiPlus, Emrah Bilbay and 18 more
Reacted by Leo, Erick, tang, Tan Jun Xiang, Javier, Martin Anderson and Naoya Yoshizawa
Reacted by Matteo Minutti and Kirill
Reacted by Mateus Gustavo de Freitas e Silva, József Barát, Raghav, Erick, tang, Javier, Fotima97 and Naoya Yoshizawa
While this isn't technically a breaking API change, in order to fix this we would be changing the current behavior of the bottom sheet implementation. For those interested I posted a breaking change announcement here:
Why just not having this configurable with a dismissable field by default to false to be material compliant?
We could add a dismissOnTap boolean field, but that would add complexity to the API for a feature that most apps would never want, and for those that do, it is simple to implement themselves.
IMHO anything modal should be dismissed only programatically. When a developer pops anything modal he does it precisely to prevent user interaction with whatever is behind it, so he should have control on how to dismiss it.
I was trying to use a modalbottomsheet to show some info while performing some async background work and I expected it to force the user to wait for it to finish but he can just tap anywhere on the screen, close the modalbottomsheet and mess with the entire workflow I need (finish loading data before being able to edit it).
Same goes for modal dialogs. Hardware back button on Android can dismiss it. When instead it should be considered part of the page and pop the entire page, not just the modal.
But for those who wants to have full control over the modal dismission, you need something like that:
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
MyModel model = Provider.of<MyModel>(context); //this is just my model doing the background work. You don't need it
return WillPopScope(
onWillPop: () async => false, //prevents Android back button and outside tap from popping it
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {}, //prevents taps inside the sheet from popping it
onVerticalDragStart: (_) {}, //prevents dragging down from popping it
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
CircularProgressIndicator(),
SizedBox(
width: 10,
),
Text(model.progressText),
],
),
),
),
);
});
showDialog only needs the WillPopScope and barrierDismissible: false, though
But honestly? This shouldn't be necessary. This should be the default behavior. All that extra code should be added IF desired, not if undesired. Having to add empty methods to prevent stuff is definitely not the best design and it looks like a real problem in Flutter. My code is full of them just to make things work as expected.
So here're my suggestions:
Add: onBackPressed callback for all modals.
Add: onOutsideTap, onInsideTap and onSwipeDown callbacks (or something like that) to ModalBottomSheet.
If set, they are enabled. If not set, they are disabled by default. Just like other Widgets on Flutter like FlatButton.
Reacted by Asher Kach, Anton Kozyriatskyi, Avinash Kumar, Lucas Aschenbach, Vladimir, Hung Nguyen and Yishai Silver
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 -v and a minimal reproduction of the issue.
Activity
Narumikun commentedon Oct 14, 2018
I'm troubling with the problem too, I wonder how you use the GestureDetector to solve the dismissing of bottom sheet when tapping its body? Could you please show me a simple code example?Have already solved, thanks a lot!
jklint-g commentedon Oct 15, 2018
For the record, the fix in our code was to wrap our bottom sheet widget like this. The buttons in the bottom sheet still worked:
yathit commentedon Nov 18, 2018
I also agree with this. Model bottom sheet should not closed, because tap does indicate interest in model, not intention to dismiss.
iamhachemi commentedon Dec 31, 2018
I also agree on this, when a user tap on the Model Bottom Sheet, it should not close it.
dominikkallusky commentedon Feb 7, 2019
This is still happening for me.
leogny commentedon Apr 27, 2019
Agreed. Model sheet should close if tapped outside but not inside unless directed to do so.
Hixie commentedon Apr 30, 2019
cc @HansMuller
marinat commentedon May 7, 2019
Dear developers, let users decide how bottom sheet will react on tap on it's body
jaumard commentedon May 9, 2019
Why just not having this configurable with a dismissable field by default to false to be material compliant?
darrenaustin commentedon May 10, 2019
While this isn't technically a breaking API change, in order to fix this we would be changing the current behavior of the bottom sheet implementation. For those interested I posted a breaking change announcement here:
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/flutter-announce/9m39PZCAKkM
Feel free to add to this ticket to provide feedback.
darrenaustin commentedon May 10, 2019
We could add a
dismissOnTapboolean field, but that would add complexity to the API for a feature that most apps would never want, and for those that do, it is simple to implement themselves.dpedrinha commentedon Sep 29, 2019
IMHO anything modal should be dismissed only programatically. When a developer pops anything modal he does it precisely to prevent user interaction with whatever is behind it, so he should have control on how to dismiss it.
I was trying to use a modalbottomsheet to show some info while performing some async background work and I expected it to force the user to wait for it to finish but he can just tap anywhere on the screen, close the modalbottomsheet and mess with the entire workflow I need (finish loading data before being able to edit it).
Same goes for modal dialogs. Hardware back button on Android can dismiss it. When instead it should be considered part of the page and pop the entire page, not just the modal.
But for those who wants to have full control over the modal dismission, you need something like that:
showDialogonly needs theWillPopScopeandbarrierDismissible: false, thoughBut honestly? This shouldn't be necessary. This should be the default behavior. All that extra code should be added IF desired, not if undesired. Having to add empty methods to prevent stuff is definitely not the best design and it looks like a real problem in Flutter. My code is full of them just to make things work as expected.
So here're my suggestions:
Add:
onBackPressedcallback for all modals.Add:
onOutsideTap,onInsideTapandonSwipeDowncallbacks (or something like that) toModalBottomSheet.If set, they are enabled. If not set, they are disabled by default. Just like other
Widgetson Flutter likeFlatButton.github-actions commentedon Aug 15, 2021
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.