【发布时间】:2020-05-11 06:14:03
【问题描述】:
我试图强制我的 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