Dart Uri.directory()
Syntax & Examples
Uri.directory constructor
The `Uri.directory` constructor in Dart is similar to `Uri.file` but ensures that a non-empty URI path ends with a slash.
Syntax of Uri.directory
The syntax of Uri.Uri.directory constructor is:
Uri.directory(String path, { bool windows })This Uri.directory constructor of Uri like Uri.file except that a non-empty URI path ends in a slash.
Parameters
| Parameter | Optional/Required | Description | 
|---|---|---|
path | required | The directory path, which can be absolute or relative. | 
windows | optional | A boolean flag indicating whether the path should be treated as a Windows path. Defaults to false. | 
✐ Examples
1 Creating a directory URI on Unix-like systems
In this example,
- We define a string variable `path` representing a Unix-like path.
 - We use the `Uri.directory` constructor to create a directory URI from this path.
 - We print the URI as a string.
 
Dart Program
void main() {
  String path = '/usr/local/bin';
  Uri uri = Uri.directory(path);
  print(uri.toString());
}Output
file:///usr/local/bin/
2 Creating a directory URI on Windows with Windows conventions
In this example,
- We define a string variable `path` representing a Windows path.
 - We use the `Uri.directory` constructor with the `windows` parameter set to true.
 - We print the URI as a string.
 
Dart Program
void main() {
  String path = 'C:\\Program Files';
  Uri uri = Uri.directory(path, windows: true);
  print(uri.toString());
}Output
file:///C:/Program%20Files/
Summary
In this Dart tutorial, we learned about Uri.directory constructor of Uri: the syntax and few working examples with output and detailed explanation for each example.