Home > OS >  Illegal argument in isolate message : (object is a FunctionType)
Illegal argument in isolate message : (object is a FunctionType)

Time:10-09

I have been using Isolates for a while now, but ever since Flutter 2.5.0 I get the following error

Unhandled Exception: Invalid argument(s): Illegal argument in isolate message : (object is a FunctionType)

Its unclear what has changed in all stable branch versions since 2.5.0 that has caused this to occur. I have been using the same compute method for some time and it has worked without any issue. I would love to correct what might be causing the issue but I cannot find any detail pertaining to this issue. Has anyone else seen this issue and subsequently found a solution?

Future<Map> callReportSubmit(Map myMap) {
  return compute(submitReport, myMap);
}

this is my calling method, it is a top Level function calling another top-level function. The map contains a datetime, 2 strings and 1 object.

CodePudding user response:

Based on https://api.flutter.dev/flutter/foundation/compute-constant.html Compute() returns eventually the value returned by the callback you passed as argument to the isolate.

try making your function asynchron:

 Future<Map> callReportSubmit(Map myMap) async{
   return await compute(submitReport, myMap);
}

CodePudding user response:

Thanks for the really good info guys, it turns out that Flutter 2.5.0 and up seems to be enforcing the parameter types even when wrapped in a map. This was implied before, but not enforced. encoding my object to json then decoding once inside of my isolate resolved the issue. please see this along with the other suggestions above. Thanks for your help!

  • Related