1

How multiple data can be send with same name parameter in post api in flutter. In php we use parameter[] and then we can send multiple data but I am new to flutter so I want to know how it can be done. thanx

Example Image: https://i.stack.imgur.com/X7jL3.png

  • Welcome to Stack Overflow! Please visit [help center](https://stackoverflow.com/help), take a [tour](https://stackoverflow.com/tour) to see what and [how to ask](https://stackoverflow.com/questions/how-to-ask). if you get stuck, post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your attempt. – Greg Jun 30 '20 at 15:33

1 Answers1

8

I hope you solved this already but in case you didn't I faced the same problem and found a workaround I had a similar API : Here

the solution is that I added a counter variable inside ' [] ' while creating the request body map.

ex: products[$counter]

so it will give each key in the body map a different name like this

 final Map<String, dynamic> body = Map<String, dynamic>();

if (this.products != null) {
  for (int i = 0; i < products.length; i++) {
    body['products[$i]'] = json.encode(products[i]);
  }

and yet it will still be recognized by the server as same name parameter.

grayHatEnigma
  • 316
  • 3
  • 9