I'm trying to use the compute() function to trigger a top level method that calls an HTTP POST.
I can see the method being executed, but then it just hangs where I do the actual post, with no errors returned.
However if I call this without calling compute, it works fine
uploadData(Map args) {
print("uploading data"); // i see this in the logs
API().uploadData(args["data"], args["user"], args["apikey"]);
}
and it's called via
compute(uploadData, {
"data": dataList,
"user": widget.userProps,
"apikey": widget.apiKey
});
lastly this is my API uploadData method
uploadData(List files, User userdata, String apikey) async {
try {
String sessionid = await _getSession();
String _base = 'http://192.168.2.13:3000/upload';
String body = json.encode({
"api": apikey,
"user": userdata.toMap(),
"data": files,
"sessionid": sessionid
});
print("I AM HERE"); // this is called
await http.post(_base,
body: body, headers: {"Content-Type": "application/json"});
print("this is not called");
} catch (e) {
print("Error"); // no error
print(e);
}
}
you have to return
, because API().uploadData
returns a future (of null, I assume). If we don't return, API().uploadData
is executed and then uploadData(Map args)
return null
value and pops out of the stack immediate; isolate has no functions, microtask queue or event queue left, it will exit.
uploadData(Map args) {
print("uploading data"); // i see this in the logs
return API().uploadData(args["data"], args["user"], args["apikey"]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With