flutter-in-action
flutter-in-action copied to clipboard
Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
最后一章按照步骤敲完,并且安装的都是最新版的插件,在android上启动一直停在首屏(黑屏)的位置,无反应,也不报错。
后来查看日志发现以下提示:
E/flutter ( 8093): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
E/flutter ( 8093): 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.
E/flutter ( 8093): If you're running a test, you can call the TestWidgetsFlutterBinding.ensureInitialized()
as the first line in your test's main()
method to initialize the binding.
根据提示把入口方法改为以下后可以正常操作: void main() { WidgetsFlutterBinding.ensureInitialized(); Global.init().then((e) => runApp(MyApp())); }