removeWave method

bool removeWave(
  1. Wave wave
)

Removes the first occurrence of the given wave from the list of waves.

Returns true if the wave was in the list, false otherwise.

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

List<Wave> waves = [wave1, wave2, wave3];

bool removed = removeWave(wave4); // false
print(waves); // [wave1, wave2, wave3]

removed = removeWave(wave2); // true
print(waves); // [wave1, wave3]

removed = removeWave(wave1); // true
print(waves); // [wave3]

removed = removeWave(wave3); // false
print(waves); // [wave3]

Implementation

bool removeWave(Wave wave) {
  if (_waves.length == 1) return false;

  return _waves.remove(wave);
}