Dart Uri queryParametersAll
Syntax & Examples


Uri.queryParametersAll property

The `queryParametersAll` property in Dart's Uri class returns the URI query split into a map according to the rules specified for FORM post in the HTML 4.01 specification. Each key and value in the returned map has been decoded.


Syntax of Uri.queryParametersAll

The syntax of Uri.queryParametersAll property is:

 Map<String, List<String>> queryParametersAll 

This queryParametersAll property of Uri returns the URI query split into a map according to the rules specified for FORM post in the HTML 4.01 specification. Each key and value in the returned map has been decoded. If there is no query the empty map is returned.

Return Type

Uri.queryParametersAll returns value of type Map<String, List<String>>.



✐ Examples

1 URI with multiple query parameters

In this example,

  1. We create a Uri object uri1 by parsing the string 'http://example.com/path?param1=value1¶m2=value2¶m1=value3'.
  2. We use the queryParametersAll property to get the query parameters as a map.
  3. We then print the result to standard output.

Dart Program

void main() {
  Uri uri1 = Uri.parse('http://example.com/path?param1=value1&amp;param2=value2&amp;param1=value3');
  Map<String, List<String>> queryParams1 = uri1.queryParametersAll;
  print('Query parameters of URI 1: $queryParams1');
}

Output

Query parameters of URI 1: {param1: [value1, value3], param2: [value2]}

2 HTTPS URI with single query parameter

In this example,

  1. We create a Uri object uri2 by parsing the string 'https://example.com/?key=value'.
  2. We use the queryParametersAll property to get the query parameters as a map.
  3. We then print the result to standard output.

Dart Program

void main() {
  Uri uri2 = Uri.parse('https://example.com/?key=value');
  Map<String, List<String>> queryParams2 = uri2.queryParametersAll;
  print('Query parameters of URI 2: $queryParams2');
}

Output

Query parameters of URI 2: {key: [value]}

3 URI without query

In this example,

  1. We create a Uri object uri3 by parsing the string 'mailto:user@example.com'.
  2. We use the queryParametersAll property, which returns an empty map as there is no query component in the URI.
  3. We then print the result to standard output.

Dart Program

void main() {
  Uri uri3 = Uri.parse('mailto:user@example.com');
  Map<String, List<String>> queryParams3 = uri3.queryParametersAll;
  print('Query parameters of URI 3: $queryParams3');
}

Output

Query parameters of URI 3: {}

Summary

In this Dart tutorial, we learned about queryParametersAll property of Uri: the syntax and few working examples with output and detailed explanation for each example.