ValidatorGroup<T extends Object> class
Groups several validators of the same type T and runs them in order.
By default it behaves like a short-circuiting form validator: it returns
the error of the first validator that fails, or null when every
validator passes. Use errors when you need every failing message at
once. Build one directly or with the & operator.
const password = ValidatorGroup([
RequiredValidator(error: 'Required'),
MinLengthValidator(min: 8, error: 'At least 8 characters'),
HasUppercaseValidator(error: 'Add an uppercase letter'),
]);
password('abc'); // 'At least 8 characters'
password.errors('abc'); // ['At least 8 characters', 'Add an uppercase…']
password('Abcdefghi'); // null
Constructors
-
ValidatorGroup(List<
Validator< validators)T> > -
Constructs a group from the given
validators.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
validators
→ List<
Validator< T> > -
The validators applied to the value, in order.
final
Methods
-
call(
T? value) → String? -
Returns the error of the first failing validator, or
nullif the value satisfies every validator. -
errors(
T? value) → List< String> - Runs every validator and returns the errors of all that failed.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator &(
Validator< T> other) → ValidatorGroup<T> -
Appends
otherto this group, returning a new ValidatorGroup. -
operator ==(
Object other) → bool -
The equality operator.
inherited