Flutter WidgetsFlutterBinding.ensureInitialized()在处理隔离内部的roo



在我的Flutter应用程序中,有一项繁重的任务迫使我使用隔离以获得流畅的UI,该任务包括使用rootBundle读取一些资产文件并在其中搜索特定文本。现在,由于呈现UI的主隔离与派生隔离不共享内存,而派生隔离将为我完成繁重的任务,每当我试图在派生隔离运行的方法中使用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.

完整的示例文件:

区块报价

最新更新