vGreaterThan<T> function
Returns a validator that requires values to be greater than 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<T> vGreaterThan<T>(dynamic compare) {
return _typedValidator<T>(
type: DraftModeValidatorType.greaterThan,
payload: compare,
delegate: (DraftModeValidationValueContext? context, T? value) {
final compareValue =
compare is Function ? compare() : context?.read(compare) ?? compare;
if (value == null || compareValue == null) {
return null;
}
if (value is DateTime && compareValue is DateTime) {
if (!value.isAfter(compareValue)) {
return DraftModeValidationGreaterThan(compareValue);
}
}
if (value is num && compareValue is num) {
if (value <= compareValue) {
return DraftModeValidationGreaterThan(compareValue);
}
}
return null;
},
);
}