url static method

FormeValidator url({
  1. String errorText = '',
  2. String? schema,
  3. String? host,
  4. int? port,
})

when valid

  1. value is null
  2. value is an url

Implementation

static FormeValidator url({
  String errorText = '',
  String? schema,
  String? host,
  int? port,
}) {
  return (f, dynamic v) {
    if (v == null || (v as String).isEmpty) {
      return null;
    }

    final Uri? uri = Uri.tryParse(v);
    if (uri == null) {
      return errorText;
    }

    if (schema != null && schema.isNotEmpty && !uri.isScheme(schema)) {
      return errorText;
    }
    if (host != null && host.isNotEmpty && uri.host != host) {
      return errorText;
    }
    if (port != null && uri.port != port) {
      return errorText;
    }

    return null;
  };
}