Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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,
              );
        });
  }
like image 494
geekymano Avatar asked Jun 12 '19 10:06

geekymano


3 Answers

Set enableDrag property of BottomSheet to false its true by default

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

Refer here for more info on BottomSheet

like image 42
Mangaldeep Pannu Avatar answered Nov 04 '22 14:11

Mangaldeep Pannu


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

showBottomSheet(
  context: context,
  builder: (context) => GestureDetector(
    child: *your_widget*,
    onVerticalDragStart: (_) {},
  ),
 
);
like image 168
Georg Panteleev Avatar answered Nov 04 '22 13:11

Georg Panteleev


If you use showModalBottomSheet, simply use enableDrag property:

showModalBottomSheet(
  context: context,
  builder: (context) => yourWidget,
  enableDrag: false,
);
like image 29
Andrey Gordeev Avatar answered Nov 04 '22 13:11

Andrey Gordeev