requiredValidator function

String? requiredValidator(
  1. String? value, [
  2. String? message
])

Validates if a value is required.

Returns an error message if the value is null or empty, otherwise returns null. The error message can be customized by providing a message parameter. If no message is provided, it will use the default message based on the current localization.

Example usage:

String? errorMessage = requiredValidator(value);
if (errorMessage != null) {
  print(errorMessage);
}

Implementation

String? requiredValidator(String? value, [String? message]) =>
    (value == null || value.isEmpty)
        ? (message ??
            (getCurrentLocalization() == 'id'
                ? 'Kolom tidak boleh kosong'
                : "Field can't be empty"))
        : null;