notEmpty function

bool notEmpty(
  1. dynamic property,
  2. ConstraintValidatorContext cvc
)

Implementation

bool notEmpty(dynamic property, ConstraintValidatorContext cvc) {
  if (property == null) {
    return true;
  } else if (property is String && property.isEmpty) {
    cvc.addTemplateViolation('Text can\'t be empty');
  } else if (property is List && property.isEmpty) {
    cvc.addTemplateViolation('List can\'t be empty');
  } else if (property is Map && property.isEmpty) {
    cvc.addTemplateViolation('Map can\'t be empty');
  } else if (property is Set && property.isEmpty) {
    cvc.addTemplateViolation('Set can\'t be empty');
  }
  return cvc.isValid();
}