removeWaveAt method

Wave? removeWaveAt(
  1. int index
)

Removes the wave at the given index from the list of waves.

Throws a RangeError if the index is out of bounds.

If the list of waves has only one wave, this method will return null and the wave will not be removed. The list must never be empty.

List<Wave> waves = [wave1, wave2, wave3];
Wave? removed = removeWaveAt(1); // wave2
print(waves); // [wave1, wave3]

removed = removeWaveAt(1); // wave3
print(waves); // [wave1]

removed = removeWaveAt(0); // null
print(waves); // [wave1]

Implementation

Wave? removeWaveAt(int index) {
  if (index < 0 || index >= _waves.length) {
    throw RangeError.range(index, 0, _waves.length - 1);
  }

  if (_waves.length == 1) return null;

  return _waves.removeAt(index);
}