apply<T extends DataGridRow> method

  1. @override
DataGridState<T>? apply<T extends DataGridRow>(
  1. EventContext<T> context
)
override

Apply this event's transformation to the state. Returns the new state, or null if no state change should occur. Can return a Future for async operations.

Implementation

@override
DataGridState<T>? apply<T extends DataGridRow>(EventContext<T> context) {
  final newRowsById = Map<double, T>.from(context.state.rowsById);
  for (final id in rowIds) {
    newRowsById.remove(id);
  }

  final newDisplayOrder = context.state.displayOrder
      .where((id) => !rowIds.contains(id))
      .toList();

  context.dataIndexer.setData(newRowsById);

  final selectedRows = Set<double>.from(
    context.state.selection.selectedRowIds,
  );
  selectedRows.removeAll(rowIds);

  return context.state.copyWith(
    rowsById: newRowsById,
    displayOrder: newDisplayOrder,
    selection: context.state.selection.copyWith(
      selectedRowIds: selectedRows,
      focusedRowId: rowIds.contains(context.state.selection.focusedRowId)
          ? null
          : context.state.selection.focusedRowId,
    ),
  );
}