![](/img/trans.png)
[英]Isolate Unhandled exception: E/flutter call the `WidgetsFlutterBinding.ensureInitialized()`
[英]Flutter WidgetsFlutterBinding.ensureInitialized() appears when dealing with rootBundle inside an isolate
在我的 Flutter 应用程序中,有一项繁重的任务迫使我使用隔离来获得流畅的 UI,该任务包括使用 rootBundle 读取一些资产文件并在它们中搜索特定文本。 现在,由于呈现 UI 的主要隔离不与生成的隔离共享 memory,这将为我完成繁重的任务,每当我尝试在生成的隔离运行的方法中使用 rootBundle 时,我都会收到此错误:
在初始化绑定之前访问了 ServicesBinding.defaultBinaryMessenger。
当然使用WidgetsFlutterBinding.ensureInitialized(); 在方法的顶部不起作用。 我尝试将 rootBundle 发送到生成的 Isolate 并在那里使用它,但这没有用。
我将此报告给 flutter 开发人员: https://github.com/flutter/flutter/issues/61480
他们回应说这不是错误,也许是原样。 检查颤振样本,您可以找到以下内容:
// Load the JSON string. This is done in the main isolate because spawned
// isolates do not have access to the root bundle. However, the loading
// process is asynchronous, so the UI will not block while the file is
// loaded.
完整的示例文件:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.