Skip to content

.uri()

Passes when the string parses as a URI with a scheme and contains no whitespace. mailto:[email protected] passes; example.com and not a uri at all fail. With allowedSchemes, the scheme has to be in the list, compared case-insensitively. For a web address with a host, use .url().

StringValidator<O> uri({List<String>? allowedSchemes, String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
allowedSchemes List<String>? Schemes to accept, such as ['https']. 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 invalidUri. Default message: value must be a valid uri, continued with . Allowed scheme is https or . Allowed schemes are http, https when schemes are given. value is replaced by the field name when there is one.

@IsUri(allowedSchemes: [...]), or the constant @isUri. A Uri field maps to l.string() without .uri(); add the annotation if you want the check. Put the annotation on the constructor parameter or the field.

final link = l.string().uri(allowedSchemes: ['https']);
link.validate(input)+2-2
  1. valid: 'https://example.com'
  2. valid: 'HTTPS://example.com'
  3. invalid: 'mailto:[email protected]'value must be a valid uri. Allowed scheme is https
  4. invalid: 'not a uri at all'value must be a valid uri. Allowed scheme is https

Without allowedSchemes, any scheme passes and a bare host fails:

true
false