url static method

String? url(
  1. String? value, {
  2. bool requireHttps = false,
})

Validates that the input is a valid URL.

Implementation

static String? url(String? value, {bool requireHttps = false}) {
  if (value == null || value.isEmpty) return 'URL is required';

  try {
    final uri = Uri.parse(value);
    if (!uri.isAbsolute) return 'Please enter a complete URL';

    if (requireHttps && !uri.scheme.startsWith('https')) {
      return 'URL must use HTTPS';
    }

    return null;
  } catch (e) {
    return 'Invalid URL format';
  }
}