Dart Uri userInfo
Syntax & Examples
Uri.userInfo property
The `userInfo` property in Dart's Uri class returns the user info part of the authority component.
Syntax of Uri.userInfo
The syntax of Uri.userInfo property is:
String userInfo
This userInfo property of Uri returns the user info part of the authority component.
Return Type
Uri.userInfo returns value of type String
.
✐ Examples
1 Getting user info from an HTTP URI with user info
In this example,
- We parse an HTTP URI with user info.
- We access the `userInfo` property of the URI.
- We print the user info to standard output.
Dart Program
void main() {
Uri uri1 = Uri.parse('https://user:pass@example.com');
print(uri1.userInfo); // user:pass
}
Output
user:pass
2 Getting user info from an FTP URI without user info
In this example,
- We parse an FTP URI without user info.
- We access the `userInfo` property of the URI.
- We print an empty string since there is no user info.
Dart Program
void main() {
Uri uri2 = Uri.parse('ftp://example.com');
print(uri2.userInfo); // '' (empty string)
}
Output
Summary
In this Dart tutorial, we learned about userInfo property of Uri: the syntax and few working examples with output and detailed explanation for each example.