首页 > 解决方案 > 通过设置为纵向模式的 xcode 在我的物理 iPhone 上启动颤振应用程序有效,但在通过 android studio 启动时无效

问题描述

在我声明了设备方向的 main.dart 文件中

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  runApp(Egenkontroll());
}

当我在我的物理 iPhone 7 上通过 xcode 启动应用程序时,我会在我想要的纵向模式下获得我的视图,但是当我通过 android studio 在我的设备纵向模式上启动时,我的设备纵向模式未启用,并且视图会根据设备方向调整,我不想要。

当我在 appstore 上发布应用程序时,这是否重要?

标签: androidiosxcodeflutter

解决方案


SystemChrome.setPreferredOrientations是异步任务,所以要么等待,要么把你的运行放在里面

 SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp])
      .then((_) =>
      runApp(Egenkontroll())
      );

或者

await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(Egenkontroll());

推荐阅读