notEmpty static method

String? Function() notEmpty(
  1. String value, {
  2. String? errorMessage,
})

Returns a validation function that checks if the input value is not empty.

The validation function will return an error message if the value is empty, otherwise it returns null indicating the value is valid.

value: The input value to validate. errorMessage: The error message to display if the validation fails. If not provided, a default message is used.

Implementation

static String? Function() notEmpty(
  String value, {
  String? errorMessage,
}) {
  return () {
    if (value.isEmpty) {
      return errorMessage ?? 'This field is required.';
    }
    return null;
  };
}