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);
  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);

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