.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().
Signature
Section titled “Signature”StringValidator<O> uri({List<String>? allowedSchemes, String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| 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.
Code generation
Section titled “Code generation”@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.
Example
Section titled “Example”final link = l.string().uri(allowedSchemes: ['https']);@IsUri(allowedSchemes: ['https']) required String homepage,// l.string().uri(allowedSchemes: ["https"]).required()link.validate(input)+2-2- valid:
'https://example.com' - valid:
'HTTPS://example.com' - invalid:
'mailto:[email protected]' - invalid:
'not a uri at all'
Without allowedSchemes, any scheme passes and a bare host fails:
truefalse