MinAgeValidator class

A validator that checks if the age calculated from the value date is greater than or equal to minAge.

The MinAgeValidator can be used with FieldControllers holding values of type DateTime. It ensures that the calculated age is at least minAge.

If the value is null, it is treated as valid by default.

Properties

  • minAge: The minimum allowed age calculated from the value date.
  • message: An optional custom error message to display when invalid.

Example

FieldController<DateTime> field = FieldController(
  key: 'birthDate',
  initialValue: DateTime(2025, 7, 12)
  validators: [MinAgeValidator(18)],
);

// If field.value = DateTime(2010, 7, 12), validation fails.
// If field.value = DateTime(2000, 7, 12), validation passes.

See also

Inheritance

Constructors

MinAgeValidator.new(int minAge, {String? message})

Properties

hashCode int
The hash code for this object.
no setterinherited
message String?
finalinherited
minAge int
The minimum allowed age calculated from the value date.
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