How to set landscape orientation mode for flutter app?

落花浮王杯 提交于 2020-05-08 08:10:13

问题


I was looking for code which can set orientation of my flutter app landscape forcefully.


回答1:


Enable forcefully

Import package: import 'package:flutter/services.dart'; in main.dart file

1. Landscape mode:

// Set landscape orientation
SystemChrome.setPreferredOrientations([
  DeviceOrientation.landscapeLeft,
  DeviceOrientation.landscapeRight,
]);

2. Portrait mode:

// Set portrait orientation
SystemChrome.setPreferredOrientations([
   DeviceOrientation.portraitDown,
   DeviceOrientation.portraitUp,
]);




回答2:


import 'package:flutter/services.dart';

void main()  {
   WidgetsFlutterBinding.ensureInitialized();
   SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft])
   .then((_) {
    runApp(new MyApp());
  });
}


来源:https://stackoverflow.com/questions/51806662/how-to-set-landscape-orientation-mode-for-flutter-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!