Is it possible to use BuildContext inside compute function?
Future<int> getFuture() async {
int r = await compute(count, context);
return r;
}
static int count(BuildContext context) {
// Something very slow.
return 10;
}
I receive the following error when attempting to pass the 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':.))
If I change the input to the count function to other normal class, it works fine.
Is there any way to fix this? Or is using BuildContext possible in an Isolate? Thanks!