passes method

  1. @override
FutureOr<bool> passes(
  1. ValidationContext context
)
override

Validates the value using the given context.

Returns true if valid, otherwise false.

Implementation

@override
FutureOr<bool> passes(ValidationContext context) {
  final value = context.value;

  // If null, it's considered empty/missing -> Pass
  if (value == null) return true;

  // If string and empty -> Pass
  if (value is String && value.trim().isEmpty) return true;

  // If collection and empty -> Pass
  if (value is Iterable && value.isEmpty) return true;
  if (value is Map && value.isEmpty) return true;

  // Otherwise, it is present and not empty -> Fail
  return false;
}