Dio: How to send an array of queryParameters?

Created on 29 May 2019  路  2Comments  路  Source: flutterchina/dio

New Issue Checklist

  • [x ] I have searched for a similar issue in the project and found none

Issue Info

| Info | Value
| ------------------------------ | --------------------------------------------------
| Platform Name | flutter
| Platform Version | 1.5.4-hotfix.2
| Dio Version | 2.1.0
| Repro rate | 100%

Issue Description and Steps

How do I send an array of queryParameters?

In postman, I am able to send a GET with an array of parameters. The URL looks like this and it works fine:

/v2/tickets?templateId=5&templateId=7

I have tried a lot of different ways to do the same in flutter with Dio and can't get it to work:

queryParameters['templateId'] = [1, 2];
queryParameters['templateId'] = ['1', '2'];
queryParameters['templateId'] = `[1, 2]`;

Most helpful comment

  var uri = Uri(
    ...
    queryParameters: {
      "templateId": ['1', '2']
    },
  );
  dio.getUri(uri);

All 2 comments

  var uri = Uri(
    ...
    queryParameters: {
      "templateId": ['1', '2']
    },
  );
  dio.getUri(uri);
  var uri = Uri(
    ...
    queryParameters: {
      "templateId": ['1', '2']
    },
  );
  dio.getUri(uri);

Thank you, works perfectly. The issue was I was using dio.get() instead of dio.getUri()

Was this page helpful?
0 / 5 - 0 ratings