How to prevent bottom sheet dismiss flutter

Viewed 2612

I want to prevent dismissing the bottom sheet on swipe down in flutter, I want to use Scaffold.of(context).showBottomSheet<void>((BuildContext context) => ...) instead of showModalBottomSheet because I need to scaffold information, is there any solution for showBottomSheet? how can I do it?

4 Answers

Wrap your widget with a GestureDetector and disable drag:

Scaffold.of(context).showBottomSheet(
  (context) => GestureDetector(
    child: YourWidget(),
    onVerticalDragStart: (_) {},
  ),
)

If you are using showModalBottomSheet use enableDrag property.

showModalBottomSheet<bool>(
        context: context,
        enableDrag: false,
        ...
        builder: (BuildContext bc) {
           return ..your widgets...
        }
);
showModalBottomSheet(
    isDismissible: false,
)

Even though @Sami answer works fine, it's not quite elegant, as it seems like a workaround.

For cases like this, you should use AbsorbPointer instead of just using an empty Gesture.

It's, simply put (pasting the docs):

A widget that absorbs pointers during hit testing.

In your case, you would use like this:

Scaffold.of(context).showBottomSheet(
  (context) => AbsorbPointer(child: Container()),
)
Related