singleOrNull property

E? singleOrNull

Returns single element, or null if the collection is empty or has more than one element.

Implementation

E? get singleOrNull {
  var found = false;
  E? single;

  for (final element in this) {
    if (found) return null;

    single = element;
    found = true;
  }

  return single;
}