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