Validator<T> class
abstract
Abstract base class for implementing form field validation logic.
Validators are responsible for checking the validity of form field values and returning appropriate validation results. They support both synchronous and asynchronous validation through the FutureOr return type.
Validators can be combined using logical operators:
&
or+
: Combines validators (all must pass)|
: Creates OR logic (at least one must pass)~
or unary-
: Negates the validator result
The generic type T
represents the type of value being validated.
Example:
final validator = RequiredValidator<String>() &
MinLengthValidator(3) &
EmailValidator();
Constructors
- Validator.new()
-
Creates a Validator.
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
Methods
-
combine(
Validator< T> other) → Validator<T> - Combines this validator with another validator using AND logic.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shouldRevalidate(
FormKey source) → bool - Determines if this validator should be re-run when the specified form key changes.
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
BuildContext context, T? value, FormValidationMode lifecycle) → FutureOr< ValidationResult?> -
Validates the given
value
and returns a validation result.
Operators
-
operator &(
Validator< T> other) → Validator<T> - Combines this validator with another using AND logic (alias for combine).
-
operator +(
Validator< T> other) → Validator<T> - Combines this validator with another using AND logic (alias for combine).
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator unary-(
) → Validator< T> -
Negates this validator's result (alias for
~
operator). -
operator |(
Validator< T> other) → Validator<T> - Combines this validator with another using OR logic.
-
operator ~(
) → Validator< T> - Negates this validator's result.