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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.