Dart Uri hasAbsolutePath
Syntax & Examples


Uri.hasAbsolutePath property

The `hasAbsolutePath` property in Dart's Uri class returns whether the URI has an absolute path (starting with '/').


Syntax of Uri.hasAbsolutePath

The syntax of Uri.hasAbsolutePath property is:

 bool hasAbsolutePath 

This hasAbsolutePath property of Uri returns whether the URI has an absolute path (starting with '/').

Return Type

Uri.hasAbsolutePath returns value of type bool.



✐ Examples

1 Checking an HTTP URI if it has an absolute path

In this example,

  1. We parse an HTTP URI without an absolute path.
  2. We access the `hasAbsolutePath` property of the URI.
  3. We print the result, which is true.

Dart Program

void main() {
  Uri uri1 = Uri.parse('https://example.com/page');
  print(uri1.hasAbsolutePath); // true
}

Output

true

2 Checking an HTTP URI with an absolute path

In this example,

  1. We parse an HTTP URI with an absolute path.
  2. We access the `hasAbsolutePath` property of the URI.
  3. We print the result, which is true since the path starts with '/'.

Dart Program

void main() {
  Uri uri2 = Uri.parse('https://example.com/page/subpage');
  print(uri2.hasAbsolutePath); // true
}

Output

true

3 Checking an FTP URI without an absolute path

In this example,

  1. We parse an FTP URI without an absolute path.
  2. We access the `hasAbsolutePath` property of the URI.
  3. We print the result, which is false since the path does not start with '/'.

Dart Program

void main() {
  Uri uri3 = Uri.parse('./path/file.txt');
  print(uri3.hasAbsolutePath); // false
}

Output

false

Summary

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