如何在颤动中将应用程序强制为人像模式 [英] How to force the application to Portrait mode in flutter

查看:71
本文介绍了如何在颤动中将应用程序强制为人像模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void main(){
  ///
  /// Force the layout to Portrait mode
  /// 
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);

  runApp(new MyApp());
}

推荐答案

将此代码放入MyApp()中,不要忘记导入服务包:

Put this code in the MyApp() and don't forget to import the services package:

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

像下面这样:

import 'package:flutter/services.dart';

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);
      return new MaterialApp();
    }
  }

更新

有一个错误,阻止该代码按照@ F-1的注释在ipads github.com/flutter/flutter/issues/27235上运行.

There is a bug which prevents this code working on ipads github.com/flutter/flutter/issues/27235 as per comment by @F-1.

下面的评论可能会帮助您.

Below comment may help you out.

https://github.com/flutter/flutter/issues/27235# issuecomment-508995063

这篇关于如何在颤动中将应用程序强制为人像模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆