KeySet<T extends KeyboardKey> constructor Null safety

KeySet<T extends KeyboardKey>(
  1. T key1,
  2. [T? key2,
  3. T? key3,
  4. T? key4]
)

A constructor for making a KeySet of up to four keys.

If you need a set of more than four keys, use KeySet.fromSet.

The same KeyboardKey may not be appear more than once in the set.

Implementation

KeySet(
  T key1, [
  T? key2,
  T? key3,
  T? key4,
])  : assert(key1 != null),
      _keys = HashSet<T>()..add(key1) {
  int count = 1;
  if (key2 != null) {
    _keys.add(key2);
    assert(() {
      count++;
      return true;
    }());
  }
  if (key3 != null) {
    _keys.add(key3);
    assert(() {
      count++;
      return true;
    }());
  }
  if (key4 != null) {
    _keys.add(key4);
    assert(() {
      count++;
      return true;
    }());
  }
  assert(_keys.length == count, 'Two or more provided keys are identical. Each key must appear only once.');
}