validate method
FutureOr<ValidationResult?>
validate(
- BuildContext context,
- T? value,
- FormValidationMode state
override
Implementation
@override
FutureOr<ValidationResult?> validate(
BuildContext context, T? value, FormValidationMode state) {
var localizations = Localizations.of(context, ShadcnLocalizations);
var compare = _compare(value, this.value);
switch (type) {
case CompareType.greater:
if (compare <= 0) {
return InvalidResult(
message ?? localizations.formGreaterThan(this.value),
state: state);
}
break;
case CompareType.greaterOrEqual:
if (compare < 0) {
return InvalidResult(
message ?? localizations.formGreaterThanOrEqualTo(this.value),
state: state);
}
break;
case CompareType.less:
if (compare >= 0) {
return InvalidResult(
message ?? localizations.formLessThan(this.value),
state: state);
}
break;
case CompareType.lessOrEqual:
if (compare > 0) {
return InvalidResult(
message ?? localizations.formLessThanOrEqualTo(this.value),
state: state);
}
break;
case CompareType.equal:
if (compare != 0) {
return InvalidResult(message ?? localizations.formEqualTo(this.value),
state: state);
}
break;
}
return null;
}