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

ParameterOptional/RequiredDescription
schemerequiredThe 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,

  1. We parse an HTTPS URI.
  2. We call the `isScheme` method with the argument 'https'.
  3. 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,

  1. We parse an FTP URI.
  2. We call the `isScheme` method with the argument 'https'.
  3. 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.