Calling cloud function from custom action

Actions & Logic

I am calling a cloud function from a custom action and I am getting errors in the chrome console

The cloud function works fine and it returns a JSON with 2 fields (I can see this in the browser). As you can see from the code I am awaiting the function so the issue should not be that

The errors I can get to flutterflow and they work fine

I am getting this in the console, this is coming from the jsonEncode. I have been trying to debug the output in many different ways but it seems the result is not available in the custom action. In the browser I can see it. I am calling the custom function on page load

converting object to an encodable object failed: instance of 'minified:tf<dynamic>'
 Future<dynamic> newCustomAction(String code, String function) async {
  try {
    final callable = FirebaseFunctions.instance.httpsCallable(function);
    final result = await callable.call({"code": code});
    var retVal = {"result": result};
    var retVal2 = jsonEncode(result);
    debugPrint(retVal.toString());
    debugPrint(retVal2);
    return {"result": result};
  } on FirebaseFunctionsException catch (error) {
    return {"message": error.message, "code": error.code};
  }
}
What have you tried so far?

Many things

Did you check FlutterFlow's Documentation for this topic?
Yes
2