Flutter: How to set and lock screen orientation on-demand

后端 未结 6 1387
南方客
南方客 2020-11-28 22:45

On one of my flutter pages, I need the screen to set to landscape mode and lock it so it can\'t rotate into portrait mode, but only on the one page. So need a way to enable

6条回答
  •  失恋的感觉
    2020-11-28 23:08

    import services.dart and your void main function should be like:

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

提交回复
热议问题