apply<T extends DataGridRow> method
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);
newRowsById.remove(rowId);
final newDisplayOrder = context.state.displayOrder
.where((id) => id != rowId)
.toList();
context.dataIndexer.setData(newRowsById);
final selectedRows = Set<double>.from(
context.state.selection.selectedRowIds,
);
selectedRows.remove(rowId);
final newTotalItems = context.state.totalItems - 1;
final pagination = context.state.pagination;
final newTotalPages = pagination.totalPages(newTotalItems);
final adjustedPage = pagination.currentPage > newTotalPages
? newTotalPages
: pagination.currentPage;
return context.state.copyWith(
rowsById: newRowsById,
displayOrder: newDisplayOrder,
totalItems: newTotalItems,
pagination: pagination.copyWith(currentPage: adjustedPage),
selection: context.state.selection.copyWith(
selectedRowIds: selectedRows,
focusedRowId: context.state.selection.focusedRowId == rowId
? null
: context.state.selection.focusedRowId,
),
);
}