validate method

  1. @override
FutureOr<ValidationResult?> validate(
  1. BuildContext context,
  2. T? value,
  3. FormValidationMode state
)
override

Implementation

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