validate method

  1. @override
String? validate(
  1. String? value
)
override

Validates the value and returns an error string if it fails, or null if it passes.

Implementation

@override
String? validate(String? value) {
  if (value == null || value.isEmpty) return null;
  final uri = Uri.tryParse(value);
  if (uri == null || !uri.hasScheme || !uri.hasAuthority) {
    return message;
  }
  if (requireHttps && uri.scheme != 'https') {
    return message;
  }
  final allowedSchemes = ['http', 'https'];
  if (!allowedSchemes.contains(uri.scheme)) {
    return message;
  }
  return null;
}