Flutter: how to prevent device orientation changes and force portrait?

前端 未结 18 1455
鱼传尺愫
鱼传尺愫 2020-12-04 05:41

I would like to prevent my application from changing its orientation and force the layout to stick to \"portrait\".

In the main.dart, I put:

void mai         


        
18条回答
  •  生来不讨喜
    2020-12-04 06:23

    Try

     void main() async {
          WidgetsFlutterBinding.ensureInitialized();
          await SystemChrome.setPreferredOrientations(
              [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); 
        
          runApp(MyApp());
     }
    

    You can also change the screen orientation settings in the android manifest and ios info.plist file.

提交回复
热议问题