validateOneOf function

void validateOneOf(
  1. List values,
  2. List<String> names
)

Validates that exactly one value in the given list is not null.

Throws a Exception when no or more than one value is not null.

Implementation

void validateOneOf(List<dynamic> values, List<String> names) {
  final match = values.singleWhereOrNull((x) => x != null);
  if (match == null) {
    throw Exception('Exactly one of $names must not be null: $values');
  }
}