2

I've already tried:

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    Orientation orientation = MediaQuery.of(context).orientation;
    (orientation == Orientation.portrait)
        ? print(orientation)
        : Navigator.pop(context);
  }

in the _BottomContentState but that gives me an error when I switch the orientation of the device.

Additionally I want the ModalBottomSheet to close if it is open, otherwise no action

th_lo
  • 461
  • 3
  • 18

1 Answers1

0

You could use an OrientationBuilder widget to programatically close your modal bottom sheet.

OrientationBuilder(
   builder: (context, orientation) {
      if (orientation == Orientation.landscape) {
         // Close your modal
      }
   }
);
Guillaume Roux
  • 6,352
  • 1
  • 13
  • 38
  • Thanks, that worked. I had to put an OrientationBuilder inside the 'showModalBottomSheet' -function not in the didChangeDependencies() method – th_lo Dec 08 '20 at 13:15