gpt4 book ai didi

Flutter:未处理的异常:在初始化绑定(bind)之前访问了 ServicesBinding.defaultBinaryMessenger

转载 作者:IT王子 更新时间:2023-10-29 06:44:37 25 4
gpt4 key购买 nike

有什么办法可以解决这个问题吗?

堆栈跟踪:

[VERBOSE-2:ui_dart_state.cc(148)] 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.
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.
#0 defaultBinaryMessenger.<anonymous closure> (package:flutter/src/services/binary_messenger.dart:73:7)
#1 defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:86:4)
#2 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62)
#3 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:35)
<asynchronous suspension>
#4 MethodChannel.invokeMapMethod (package:f<…>

最佳答案

升级Flutter时引入该问题。这背后的原因是您正在等待一些数据或在 main() 中运行 async 函数。

我正在 main() 中初始化 ScopedModel 并在其中等待一些数据。

有一个非常小的修复。只需在 void main() 中运行 WidgetsFlutterBinding.ensureInitialized(),然后再执行 runApp()。很有魅力!!

void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(Delta(
model: ProductDataModel(),
));
}

关于Flutter:未处理的异常:在初始化绑定(bind)之前访问了 ServicesBinding.defaultBinaryMessenger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57689492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com