isValidValue<T> static method

bool isValidValue<T>(
  1. T value,
  2. List<T> validValues
)

Returns true if the the given value is found within validValues or if the validValues list is empty and value is empty as well.

Implementation

static bool isValidValue<T>(T value, List<T> validValues) {
  if (value == null) return false;

  // Let empty values pass.
  if (value is String) {
    if (value.isEmpty) return true;
  } else if (value is Iterable) {
    if (value.isEmpty) return true;
  }

  return validValues.contains(value);
}