3

Using Flutter/Dart- i'd like to make a Uri network call with queryParameters that include arrays.

Ex:

Map<String, dynamic> queryParameters = {
        'include': 'messages',
        'scopes': ['withHasUnreadMessages', 'withSubscriberUserIds'],
};
uri = Uri.https(_getBaseUrl(), '/mypath', queryParameters);

Which prints:

https://mypath?include=subscribers&scopes=withHasUnreadMessages&scopes=withSubscriberUserIds

However, my api server (PHP) doesn't play nicely with requests that include duplicate keys. My server wants:

https://mypath?include=subscribers&scopes[]=withHasUnreadMessages&scopes[]=withSubscriberUserIds

Is there a way to add brackets to darts Uri queryParameters?

PS - This might have been a comment https://stackoverflow.com/a/57367680/6010500 but i don't have the reputation points.

1

1 Answer 1

7

Not a dart user, but from first glance, you can add the array brackets to the input name

Map<String, dynamic> queryParameters = {
        'include': 'messages',
        'scopes[]': ['withHasUnreadMessages', 'withSubscriberUserIds'],
};
uri = Uri.https(_getBaseUrl(), '/mypath', queryParameters);
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.