Dart Uri.https()
Syntax & Examples
Uri.https constructor
The `Uri.https` constructor in Dart is used to create a new `https` URI from an authority, path, and optional query parameters.
Syntax of Uri.https
The syntax of Uri.Uri.https constructor is:
Uri.https(String authority, [ String unencodedPath, [ Map<String, String> queryParameters ])This Uri.https constructor of Uri creates a new https URI from authority, path and query.
Parameters
| Parameter | Optional/Required | Description | 
|---|---|---|
authority | required | The authority part of the URI, typically the domain name or IP address. | 
unencodedPath | optional | The path part of the URI. It should not be URL-encoded. | 
queryParameters | optional | A map of query parameters as key-value pairs. | 
✐ Examples
1 Creating an HTTPS URI with authority, path, and query parameters
In this example,
- We define a `String` variable `authority` with the value 'example.com'.
 - We define a `String` variable `path` with the value '/path/to/resource'.
 - We define a `Map
` variable `queryParameters` containing query parameters 'param1=value1' and 'param2=value2'.  - We use the `Uri.https` constructor to create an HTTPS URI with the specified authority, path, and query parameters.
 - We print the URI to standard output.
 
Dart Program
void main() {
  String authority = 'example.com';
  String path = '/path/to/resource';
  Map<String, String> queryParameters = {'param1': 'value1', 'param2': 'value2'};
  Uri httpsUri = Uri.https(authority, path, queryParameters);
  print(httpsUri);
}Output
https://example.com/path/to/resource?param1=value1¶m2=value2
2 Creating an HTTPS URI with authority and path only
In this example,
- We define a `String` variable `authority` with the value 'sub.example.com'.
 - We define a `String` variable `path` with the value '/file'.
 - We use the `Uri.https` constructor to create an HTTPS URI with the specified authority and path.
 - We print the URI to standard output.
 
Dart Program
void main() {
  String authority = 'sub.example.com';
  String path = '/file';
  Uri httpsUri = Uri.https(authority, path);
  print(httpsUri);
}Output
https://sub.example.com/file
Summary
In this Dart tutorial, we learned about Uri.https constructor of Uri: the syntax and few working examples with output and detailed explanation for each example.