onSelectedRowsChanged method Null safety

  1. @override
void onSelectedRowsChanged()
override

Called when the selectedRows property in SfDataGrid.controller is changed.

Implementation

@override
void onSelectedRowsChanged() {
  final DataGridConfiguration dataGridConfiguration =
      _dataGridStateDetails!();

  if (dataGridConfiguration.selectionMode != SelectionMode.multiple ||
      dataGridConfiguration.selectionMode == SelectionMode.none) {
    return;
  }

  final List<DataGridRow> newValue =
      dataGridConfiguration.controller.selectedRows.toList(growable: false);

  if (newValue.isEmpty) {
    _clearSelectedRows(dataGridConfiguration);
    notifyListeners();
    return;
  }

  _clearSelectedRows(dataGridConfiguration);
  for (final DataGridRow record in newValue) {
    _addSelection(record, dataGridConfiguration);
  }

  if (dataGridConfiguration.navigationMode == GridNavigationMode.cell &&
      _selectedRows.isNotEmpty) {
    final DataGridRow lastRecord = _selectedRows.last;
    _addCurrentCell(lastRecord, dataGridConfiguration,
        isSelectionChanging: true);
  } else if (dataGridConfiguration.isDesktop &&
      dataGridConfiguration.navigationMode == GridNavigationMode.row) {
    final DataGridRow lastRecord = _selectedRows.last;
    final int rowIndex =
        selection_helper.resolveToRowIndex(dataGridConfiguration, lastRecord);
    dataGridConfiguration.currentCell._updateBorderForMultipleSelection(
        dataGridConfiguration,
        nextRowColumnIndex: RowColumnIndex(rowIndex, -1));
  }

  notifyListeners();
}