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

后端 未结 6 1402
南方客
南方客 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:06

    Sometimes it could not work due to null info about orientation. You can use it simply like this:

    import services.dart
    
    
    void main() {
        SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitUp]
         )
            .then((_) {
              runApp(new MyApp());
            });
        }
    

    // wait for settings screen orientation after initiating app and -> then lock orientation

提交回复
热议问题