0

I'm trying to make a POST request using dart's http package with json data as the body, I'm using a variable of type dynamic to create the json object and so far it works perfectly as long as all the values in the object are strings.

If I assign the value of a property to be an int or List<int> (expecting it to be converted to an array, as expected by the server) dart crashes due to expecting either a Map<String, String> or a List<int> as the type for the body (the exact type it expects is dynamic, but it tries to cast it to Map<String, String> or List<int>).

My question is, is there any workaround to making a http POST request in dart using a object with dynamic property values?

effy
  • 410
  • 8
  • 20

1 Answers1

1

I was able to resolve this issue by using the HttpClient & HttpClientRequest classes from the dart:io package.

I stored the body as a Map<String, dynamic> and json encoded it before writing it to the request stream.

effy
  • 410
  • 8
  • 20