How can I convert the response of a http.MultipartRequest POST method in a map<String, dynamic> in Flutter?

Issue

I am using the following approach:

 var request = http.MultipartRequest('POST', Uri.parse(urlAdicionaItem));
 request.fields["comanda"] = numeroComanda.toString();
 request.fields["produto"] = idProduto.toString();
 request.fields["quantidade"] = quantidade.toString();

 var res = await request.send(); 

But I don’t know how to convert res.stream in the response.body to process data like using a regular http.post method.

Solution

In your code example res will be a StreamedResponse which can be turned into a String like this:

final responseString = await response.stream.bytesToString();

Answered By – dumazy

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.