Home > Blockchain >  Block landscape mode in flutter only for one page | Flutter
Block landscape mode in flutter only for one page | Flutter

Time:12-08

I want to block the landscape mode for some pages in my application and that page should always be in portrait. I Tried some code but that make entire application portrait.

CodePudding user response:

In initState you can set portrait like following.

@override
  void initState() {
    super.initState();

    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
 }

Then on dispose method you can set all mode you want like following.

@override
  void dispose() {
    super.dispose();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]);
  }
  • Related