how to prevent flutter showBottomSheet from being dismissed by dragging down?

Viewed 6390

I am using showBottomSheet in flutter to show a persistent bottom sheet. how can I prevent flutter showBottomSheet from being dismissed by dragging down? I have added my code below. you can place a rawmaterialbutton and with onpressed call this function.

  void itemChooser(
      {int currentItemCount, String name, callBack, BuildContext context}) {
    int chosen = 0;
    showBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Container(
              height: 500,
              color: Colors.white,
              );
        });
  }
3 Answers

Just wrap your child with GestureDetector and set onVerticalDragStart: (_) {},

showBottomSheet(
  context: context,
  builder: (context) => GestureDetector(
    child: *your_widget*,
    onVerticalDragStart: (_) {},
  ),
 
);

Set enableDrag property of BottomSheet to false its true by default

BottomSheet(
  enableDrag: false,
  builder: //builder
),

Refer here for more info on BottomSheet

If you use showModalBottomSheet, simply use enableDrag property:

showModalBottomSheet(
  context: context,
  builder: (context) => yourWidget,
  enableDrag: false,
);
Related