BetweenDatesValidator class
A validator that checks if the value date is between minDate and maxDate.
The BetweenDatesValidator can be used with FieldControllers holding
values of type DateTime
. It ensures that the
value is is between minDate and maxDate.
If the value is null
, it is treated as valid by default.
Properties
- minDate: The minimum allowed date for the value.
- maxDate: The maximum allowed date for the value.
- message: An optional custom error message to display when invalid.
Example
FieldController<DateTime> field = FieldController(
key: 'date',
validators: [BetweenDatesValidator(minDate: DateTime(2025, 7, 12), maxDate: DateTime(2025, 7, 14))],
);
// If field.value = DateTime(2025, 7, 11), validation fails.
// If field.value = DateTime(2025, 7, 15), validation fails.
// If field.value = DateTime(2025, 7, 12), validation passes.
// If field.value = DateTime(2025, 7, 13), validation passes.
// If field.value = DateTime(2025, 7, 14), validation passes.
See also
- FormyValidator, the base class for custom validators.
- ValidationResult, which describes the outcome of validation.
- FieldController, which holds the field value to be validated.
- Inheritance
-
- Object
- FormyValidator<
DateTime> - BetweenDatesValidator
Constructors
- BetweenDatesValidator.new({required DateTime minDate, required DateTime maxDate, String? message})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxDate → DateTime
-
The maximum allowed date for the value.
final
- message → String?
-
finalinherited
- minDate → DateTime
-
The minimum allowed date for the value.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call(
FieldController< DateTime> controller) → ValidationResult -
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onValidate(
FieldController< DateTime> controller) → ValidationResult -
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited