Dart Uri hasEmptyPath
Syntax & Examples
Uri.hasEmptyPath property
The `hasEmptyPath` property in Dart's Uri class returns whether the URI has an empty path.
Syntax of Uri.hasEmptyPath
The syntax of Uri.hasEmptyPath property is:
bool hasEmptyPath
This hasEmptyPath property of Uri returns whether the URI has an empty path.
Return Type
Uri.hasEmptyPath returns value of type bool
.
✐ Examples
1 Checking an HTTP URI with an empty path
In this example,
- We parse an HTTP URI with an empty path.
- We access the `hasEmptyPath` property of the URI.
- We print the result, which is true since the path is empty.
Dart Program
void main() {
Uri uri1 = Uri.parse('https://example.com');
print(uri1.hasEmptyPath); // true
}
Output
true
2 Checking an FTP URI with a non-empty path
In this example,
- We parse an FTP URI with a non-empty path.
- We access the `hasEmptyPath` property of the URI.
- We print the result, which is false since the path is not empty.
Dart Program
void main() {
Uri uri3 = Uri.parse('ftp://example.com/file.txt');
print(uri3.hasEmptyPath); // false
}
Output
false
Summary
In this Dart tutorial, we learned about hasEmptyPath property of Uri: the syntax and few working examples with output and detailed explanation for each example.