1

I use showModalBottomSheet to render a bottom sheet with buttons (StatefulWidgetWithButtons). Once a button is pressed the state of the sheet changes and it gets re-rendered with different content.

I would like that depending on a certain state the sheet becomes not dismissable. I can achieve this using

showModalBottomSheet(
  isDismissable: false
  builder: (context) => StatefulWidgetWithButtons()  
)

however what I want to achieve is that depending on a certain button pressed within StatefulWidgetWithButtons the isDismissable property changes to true (or false).

I don't know how to achieve this since I know I can change the StatefulWidgetWithButtons but that won't rebuild the bottom sheet.

I also don't want to close and show again the bottom sheet but change its dismissable behaviour while it is rendered

alexlipa
  • 1,131
  • 2
  • 12
  • 27

1 Answers1

0

I was able to get this behaviour by wrapping the non-dismissible layout variant of the bottom sheet in a GestureDetector with vertical drag handler like so:

GestureDetector(
  onVerticalDragUpdate: (_) {},
  child: ...

This prevents the default modal bottom sheet drag handlers from taking action

If you want to learn more about this solution and how it works you can read about it here: https://stackoverflow.com/a/71622120/11676468

It definitely seems more like a workaround/hack but it looks like the only alternative is to implement a completely custom showModalBottomSheet from scratch

Nikita Eroshin
  • 101
  • 1
  • 3