强制颤动时发生肖像方向错误>>

问题描述 投票:-1回答:1

我正在尝试强制我的Flutter应用仅使用人像模式。我的main()方法看起来像这样。

void main() {
  SystemChrome.setSystemUIOverlayStyle(uiOverlayStyle);
  SystemChrome.setPreferredOrientations(ALLOWED_ORIENTATIONS)
  .then((_) => runApp(MyApp()));
}

这里是ALLOWED_ORIENTATIONS的定义:

const List<DeviceOrientation> ALLOWED_ORIENTATIONS = [
  DeviceOrientation.portraitUp
];

我刚刚将所有设置等分离到另一个文件中,以便以后进行修改。

运行此代码时,出现以下错误。

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception:
ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
If you're running an application and need to access the binary messenger before `runApp()`
has been called (for example, during plugin initialization), then you need to explicitly
call the `WidgetsFlutterBinding.ensureInitialized()` first.

看来有些竞赛条件正在失败。我只是不确定是什么原因造成的。删除SystemChrome.setPreferredOrientations()行可使应用程序按预期进行编译。因此,我认为该错误与该行有关。

有什么建议吗?

我正在尝试强制我的Flutter应用仅使用人像模式。我的main()方法看起来像这样。 void main(){SystemChrome.setSystemUIOverlayStyle(uiOverlayStyle); SystemChrome ....

flutter
1个回答
-1
投票

就像错误说

© www.soinside.com 2019 - 2024. All rights reserved.