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,
- We create a Uri object
uri1
by parsing the string 'http://example.com/path?param1=value1¶m2=value2¶m1=value3'. - We use the
queryParametersAll
property to get the query parameters as a map. - We then print the result to standard output.
Dart Program
void main() {
Uri uri1 = Uri.parse('http://example.com/path?param1=value1&param2=value2&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,
- We create a Uri object
uri2
by parsing the string 'https://example.com/?key=value'. - We use the
queryParametersAll
property to get the query parameters as a map. - 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,
- We create a Uri object
uri3
by parsing the string 'mailto:user@example.com'. - We use the
queryParametersAll
property, which returns an empty map as there is no query component in the URI. - 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.