Dart Uri hasQuery
Syntax & Examples


Uri.hasQuery property

The `hasQuery` property in Dart's Uri class returns whether the URI has a query part.


Syntax of Uri.hasQuery

The syntax of Uri.hasQuery property is:

 bool hasQuery 

This hasQuery property of Uri returns whether the URI has a query part.

Return Type

Uri.hasQuery returns value of type bool.



✐ Examples

1 URI with query part

In this example,

  1. We create a Uri object uri1 by parsing the string 'http://example.com/path?query=value'.
  2. We use the hasQuery property to check if the URI has a query part.
  3. We then print the result to standard output.

Dart Program

void main() {
  Uri uri1 = Uri.parse('http://example.com/path?query=value');
  bool hasQuery1 = uri1.hasQuery;
  print('URI 1 has query: $hasQuery1');
}

Output

URI 1 has query: true

2 URI without query part

In this example,

  1. We create a Uri object uri2 by parsing the string 'mailto:user@example.com'.
  2. We use the hasQuery property to check if the URI has a query part.
  3. We then print the result to standard output.

Dart Program

void main() {
  Uri uri2 = Uri.parse('mailto:user@example.com');
  bool hasQuery2 = uri2.hasQuery;
  print('URI 2 has query: $hasQuery2');
}

Output

URI 2 has query: false

3 URI without scheme

In this example,

  1. We create a Uri object uri3 by parsing the string 'file:///path/to/file'.
  2. We use the hasQuery property to check if the URI has a query part.
  3. We then print the result to standard output.

Dart Program

void main() {
  Uri uri3 = Uri.parse('file:///path/to/file');
  bool hasQuery3 = uri3.hasQuery;
  print('URI 3 has query: $hasQuery3');
}

Output

URI 3 has query: false

Summary

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