selectCellAt method

void selectCellAt(
  1. int visibleRow,
  2. int col, {
  3. bool additive = false,
  4. bool range = false,
})

Implementation

void selectCellAt(int visibleRow, int col, {bool additive = false, bool range = false}) {
  if (!_isCellMode || col < 0 || col >= colCount) return;
  final master = _masterOf(visibleRow);
  if (master < 0) return;
  _activeMaster = master;
  _activeCol = col;
  if (selectionMode == ReadableSelectionMode.singleCell) {
    _selCells
      ..clear()
      ..add(ReadableCell(master, col));
    _anchorMaster = master;
    _anchorCol = col;
  } else if (range) {
    var anchorV = _visibleOf(_anchorMaster);
    if (anchorV < 0) anchorV = visibleRow;
    final loV = math.min(anchorV, visibleRow);
    final hiV = math.max(anchorV, visibleRow);
    final loC = math.min(_anchorCol, col);
    final hiC = math.max(_anchorCol, col);
    if (!additive) _selCells.clear();
    for (var vr = loV; vr <= hiV; vr++) {
      final m = _masterOf(vr);
      if (m < 0) continue;
      for (var c = loC; c <= hiC; c++) {
        _selCells.add(ReadableCell(m, c));
      }
    }
  } else if (additive) {
    final cell = ReadableCell(master, col);
    _selCells.contains(cell) ? _selCells.remove(cell) : _selCells.add(cell);
    _anchorMaster = master;
    _anchorCol = col;
  } else {
    _selCells
      ..clear()
      ..add(ReadableCell(master, col));
    _anchorMaster = master;
    _anchorCol = col;
  }
  notifyListeners();
}