ConditionalValidator<T> class
A validator that applies conditional validation based on form state.
ConditionalValidator only executes validation when a predicate condition is met. This allows validation rules to depend on other form field values or dynamic conditions.
Example:
ConditionalValidator<String>(
(context, value, getFieldValue) async {
final country = await getFieldValue('country');
return country == 'US';
},
message: 'ZIP code required for US addresses',
dependencies: ['country'],
)
Constructors
-
ConditionalValidator(FuturePredicate<
T> predicate, {required String message, List<FormKey> dependencies = const []}) -
Creates a ConditionalValidator with the specified predicate and dependencies.
const
Properties
-
dependencies
→ List<
FormKey> -
List of form field keys this validator depends on.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- message → String
-
The error message to display when validation fails.
final
-
predicate
→ FuturePredicate<
T> -
The predicate function that determines if validation should be applied.
final
- 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.
inherited
-
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.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
BuildContext context, T? value, FormValidationMode lifecycle) → FutureOr< ValidationResult?> -
Validates the given
valueand returns a validation result.override
Operators
-
operator &(
Validator< T> other) → Validator<T> -
Combines this validator with another using AND logic (alias for combine).
inherited
-
operator +(
Validator< T> other) → Validator<T> -
Combines this validator with another using AND logic (alias for combine).
inherited
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator unary-(
) → Validator< T> -
Negates this validator's result (alias for
~operator).inherited -
operator |(
Validator< T> other) → Validator<T> -
Combines this validator with another using OR logic.
inherited
-
operator ~(
) → Validator< T> -
Negates this validator's result.
inherited