Dart Uri isScheme()
Syntax & Examples
Uri.isScheme() method
The `isScheme` method in Dart's Uri class checks whether the scheme of the Uri is equal to a specified scheme.
Syntax of Uri.isScheme()
The syntax of Uri.isScheme() method is:
bool isScheme(String scheme) This isScheme() method of Uri whether the scheme of this Uri is scheme.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
scheme | required | The scheme to compare against. |
Return Type
Uri.isScheme() returns value of type bool.
✐ Examples
1 Checking scheme equality for an HTTPS URI
In this example,
- We parse an HTTPS URI.
- We call the `isScheme` method with the argument 'https'.
- We print the result, which is true since the schemes match.
Dart Program
void main() {
Uri uri1 = Uri.parse('https://example.com');
print(uri1.isScheme('https')); // true
}Output
true
2 Checking scheme equality for an FTP URI
In this example,
- We parse an FTP URI.
- We call the `isScheme` method with the argument 'https'.
- We print the result, which is false since the schemes do not match.
Dart Program
void main() {
Uri uri2 = Uri.parse('ftp://example.com');
print(uri2.isScheme('https')); // false
}Output
false
Summary
In this Dart tutorial, we learned about isScheme() method of Uri: the syntax and few working examples with output and detailed explanation for each example.