selectRowAt method

void selectRowAt(
  1. int index, {
  2. bool additive = false,
  3. bool range = false,
})

Select the row at visible index. additive toggles it within the existing selection (multi only); range extends from the anchor.

Implementation

void selectRowAt(int index, {bool additive = false, bool range = false}) {
  if (!_isRowMode) return;
  final master = _masterOf(index);
  if (master < 0) return;
  _activeMaster = master;
  if (selectionMode == ReadableSelectionMode.singleRow) {
    _selRows
      ..clear()
      ..add(master);
    _anchorMaster = master;
  } else if (range) {
    var anchorV = _visibleOf(_anchorMaster);
    if (anchorV < 0) anchorV = index;
    final lo = math.min(anchorV, index);
    final hi = math.max(anchorV, index);
    if (!additive) _selRows.clear();
    for (var i = lo; i <= hi; i++) {
      final m = _masterOf(i);
      if (m >= 0) _selRows.add(m);
    }
  } else if (additive) {
    _selRows.contains(master) ? _selRows.remove(master) : _selRows.add(master);
    _anchorMaster = master;
  } else {
    _selRows
      ..clear()
      ..add(master);
    _anchorMaster = master;
  }
  notifyListeners();
}