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