.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.
Signature
Section titled “Signature”StringValidator<O> url({List<String>? allowedSchemes, String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| 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.
Code generation
Section titled “Code generation”@IsUrl(allowedSchemes: [...]), or the constant @isUrl. Put the annotation on the constructor parameter or the field.
Example
Section titled “Example”final avatar = l.string().url();@IsUrl() required String avatar, // l.string().url().required()avatar.validate(input)+1-2- valid:
'https://example.com/docs' - invalid:
'example.com' - invalid:
'mailto:[email protected]'
[value must be a valid URL. Allowed scheme is https]