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) {
if (context.state.selection.mode == SelectionMode.none) {
return null;
}
if (context.canSelectRow != null && !context.canSelectRow!(rowId)) {
return null;
}
final selectedRows = Set<double>.from(
context.state.selection.selectedRowIds,
);
if (multiSelect) {
if (selectedRows.contains(rowId)) {
selectedRows.remove(rowId);
} else {
selectedRows.add(rowId);
}
} else {
if (selectedRows.contains(rowId) && selectedRows.length == 1) {
selectedRows.clear();
} else {
selectedRows.clear();
selectedRows.add(rowId);
}
}
return context.state.copyWith(
selection: context.state.selection.copyWith(
selectedRowIds: selectedRows,
focusedRowId: rowId,
),
);
}