vAfterOrEqual function

DraftModeValidator<DateTime> vAfterOrEqual(
  1. dynamic compare
)

Returns a validator that requires DateTime values to be after or equal to compare.

The compare argument may be a literal value, another attribute readable from the validation context, or a callback that resolves the comparison lazily.

Implementation

DraftModeValidator<DateTime> vAfterOrEqual(dynamic compare) {
  return _typedValidator<DateTime>(
    type: DraftModeValidatorType.afterOrEqual,
    payload: compare,
    delegate: (DraftModeValidationValueContext? context, DateTime? value) {
      final compareValue =
          compare is Function ? compare() : context?.read(compare) ?? compare;
      if (value == null || compareValue == null) {
        return null;
      }
      if (compareValue is! DateTime) {
        return null;
      }
      if (value.isBefore(compareValue)) {
        return DraftModeValidationAfterOrEqual(compareValue);
      }
      return null;
    },
  );
}