是否可以在计算函数中使用 BuildContext?
Future<int> getFuture() async {
int r = await compute(count, context);
return r;
}
static int count(BuildContext context) {
// Something very slow.
return 10;
}
尝试传递context
to时收到以下错误compute
:
I/flutter ( 8764): AsyncSnapshot<int>(ConnectionState.done, null, Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '_handleBuildScheduled@374399801':.))
如果我将计数函数的输入更改为其他普通类,它工作正常。
有没有什么办法解决这一问题?或者是否可以在Isolate中使用 BuildContext ?谢谢!