0
votes

I am trying to do an HTTP Post request, which used to work, but all of a sudden (I suppose some updates) it does not work anymore. Here it is the function:

Future<int> postQuestion(User userOwner, User userAsked, String questionText, int qoinsTotal, int votes) async {
var dateAndTime = new DateTime.now().toUtc();
Map<String, String> headers = {"Content-type": "application/json", "Authorization": "Bearer $_token"};
String jsonDoc = '{"UserOwner": "${userOwner.username}", "UserAsked": "${userAsked.username}", "UserAskedId": ${userAsked.userId}, '
            '"QuestionText": "$questionText", "QoinsTotal": $qoinsTotal, "Votes": $votes, "DateAndTime": "$dateAndTime"}';

var uriResponse = await this.client.post(_baseURLAPI+"question/${userOwner.userId}", headers: headers, body: jsonDoc);
return uriResponse.statusCode; //It must be 201

}

I get the following error: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type '(HttpException) => Null' is not a subtype of type '(dynamic) => dynamic'

The issue is that the request goes through (the API it communicates with receives the request and it does what is it supposed to do), so I am not sure why the error appears.

I have no idea what to do, I am really lost.

Thank you in advance.

1
Does the error come as a result of a bug? I mean, is there a bug in your app related to this error? I'm guessing that the error is not related to the function you posted above - sudo_kaizen
The error appears from the post request. The http post request goes through (I can clearly see that the API receives the request), and I assume when it gets the response back, it fails. - Vlad Hondru

1 Answers

0
votes

I have solved the issue. The problem was the returned json document, which was incorrect (thus, the error, as practically it received an incorrect json document i.e. the json document did not finish with a '}').