0

I'm using showModalBottomSheet to show a modal material design bottom sheet.

showModalBottomSheet<void>(
  context: context,
  builder: (BuildContext context) {
  ...

I'd like this bottom sheet to automatically close (pop?) when Flutter Android app is paused (for example the user is tapping the home button).

How can I do this?

TechAurelian
  • 5,561
  • 5
  • 50
  • 65

2 Answers2

1

Check WidgetsBindingObserver: https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html. You can extend it in your modal widget and call pop() when the app state is paused.

Nazarii Kahaniak
  • 461
  • 3
  • 11
0

Code to detect if user pressed home / tab on flutter? might be a viable solution?

If you detect a pause change in the app lifecycle you can probably then make a navigator.of(context).pop ?

BLKKKBVSIK
  • 3,128
  • 2
  • 13
  • 33