toUri property

Uri? toUri

Converts the string to a Uri object. Returns null if the conversion fails or the URL is invalid.

Example:

print('https://example.com'.toUri); // Output: Instance of 'Uri'
print('abc'.toUri); // Output: null

Implementation

Uri? get toUri => isValidUrl ? Uri.tryParse(this) : null;