Skip to content

.url()

Passes when the string parses as a URI that has both a scheme and a host, and, with allowedSchemes, a scheme in that list, compared case-insensitively. The host and port are not checked further. example.com fails for lack of a scheme, mailto:[email protected] for lack of a host.

StringValidator<O> url({List<String>? allowedSchemes, String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
allowedSchemes List<String>? Schemes to accept. params['allowedSchemes'].
message String? Replaces the default error message.
messageBuilder MessageBuilder? Builds the message from the issue. message wins when both are given. See Message builders.

Code invalidUrl. Default message: value must be a valid URL, continued with the same . Allowed scheme is ... suffix as .uri(). value is replaced by the field name when there is one.

@IsUrl(allowedSchemes: [...]), or the constant @isUrl. Put the annotation on the constructor parameter or the field.

final avatar = l.string().url();
avatar.validate(input)+1-2
  1. valid: 'https://example.com/docs'
  2. invalid: 'example.com'value must be a valid URL
  3. invalid: 'mailto:[email protected]'value must be a valid URL
[value must be a valid URL. Allowed scheme is https]