validateWithSingleError method

  1. @override
String? validateWithSingleError(
  1. dynamic value
)
override

Validates the given value and returns a single error message if invalid.

Returns null if the value is valid.

This method must be implemented by subclasses to define custom validation logic.

Implementation

@override
String? validateWithSingleError(value) {
  if (value == null) return loc.thisFieldIsRequired;

  bool isEmpty = false;
  if (value is String) {
    isEmpty = value.trim().isEmpty;
  } else if (value is Map) {
    isEmpty = value.isEmpty;
  }

  return isEmpty ? loc.thisFieldIsRequired : null;
}