l, the validator factory
l is the single instance of ValidatorFactory. Every validator starts with one of its type methods, and it holds the settings that apply to every validation in the isolate.
Type methods
Section titled “Type methods”| Method | Returns | Output type before and after .required() |
|---|---|---|
string() |
StringValidator |
String?, String |
int() |
NumberValidator<int, _> |
int?, int |
double() |
NumberValidator<double, _> |
double?, double |
num() |
NumberValidator<num, _> |
num?, num |
bool() |
BoolValidator |
bool?, bool |
list(element) |
ListValidator<E, _> |
List<E>?, List<E> |
map() |
MapValidator<K, V, _> |
Map<K, V>?, Map<K, V> |
schema(fields) |
SchemaValidator |
Map<String, Object?>?, Map<String, Object?> |
union(options) |
UnionValidator |
Object?, Object |
oneOf(values) |
OneOfValidator<T, _> |
T?, T |
file() |
FileValidator |
Object?, Object |
any() |
AnyValidator |
Object?, Object |
nullValue() |
NullValidator |
Null; has no required() |
Type methods exist only on l. l.string().int() does not compile. Every type method except any() takes message and messageBuilder for its type check. IntValidator, DoubleValidator and NumValidator are typedefs for the three NumberValidator forms.
Settings
Section titled “Settings”| Setting | Type | Default | Meaning |
|---|---|---|---|
l.messageBuilder |
MessageBuilder? |
null |
Builds the message of every issue that has no message or messageBuilder of its own. Message builders. |
l.maxDepth |
int |
512, also ValidatorFactory.defaultMaxDepth |
How deep schemas, lists, maps and unions may nest inside a value before validation stops with a tooDeep issue. Max depth. |
Both are read when validate is called, so a change applies to validators built earlier.
print(l.maxDepth);l.maxDepth = 4;// ...l.maxDepth = ValidatorFactory.defaultMaxDepth;print(l.maxDepth);512