toggle method

void toggle(
  1. int index
)

Toggles selection of an index.

In single-select mode, this replaces the current selection. In multi-select mode, this adds or removes the index.

Implementation

void toggle(int index) {
  if (multiSelect) {
    if (_selected.contains(index)) {
      _selected.remove(index);
    } else {
      _selected.add(index);
    }
  } else {
    // Single select: replace selection
    _selected.clear();
    _selected.add(index);
  }
}