isValidUrl property

bool get isValidUrl

Checks if the string is a valid URL.

Returns true if the string can be parsed as a valid HTTP or HTTPS URL.

Example:

'https://example.com'.isValidUrl; // true
'not-a-url'.isValidUrl; // false

Implementation

bool get isValidUrl {
  try {
    final uri = Uri.parse(this);
    return uri.hasScheme && (uri.scheme == 'http' || uri.scheme == 'https');
  } catch (_) {
    return false;
  }
}