Dart Uri toString()
Syntax & Examples
Uri.toString() method
The `toString` method in Dart's Uri class returns the normalized string representation of the URI.
Syntax of Uri.toString()
The syntax of Uri.toString() method is:
String toString()
This toString() method of Uri returns the normalized string representation of the URI.
Return Type
Uri.toString() returns value of type String
.
✐ Example
1 String representation of a URI
In this example,
- We create a Uri object
uri
by parsing the string 'https://example.com/path/to/resource?query=value#fragment'. - We use the
toString
method to get the string representation of the URI. - We then print the result to standard output.
Dart Program
void main() {
Uri uri = Uri.parse('https://example.com/path/to/resource?query=value#fragment');
String uriString = uri.toString();
print('String representation of URI: $uriString');
}
Output
String representation of URI: https://example.com/path/to/resource?query=value#fragment
Summary
In this Dart tutorial, we learned about toString() method of Uri: the syntax and few working examples with output and detailed explanation for each example.