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;
}
final selectedRows = Set<double>.from(
context.state.selection.selectedRowIds,
);
final startIdx = context.state.displayOrder.indexOf(startRowId);
final endIdx = context.state.displayOrder.indexOf(endRowId);
if (startIdx == -1 || endIdx == -1) {
return null;
}
final minIdx = startIdx < endIdx ? startIdx : endIdx;
final maxIdx = startIdx < endIdx ? endIdx : startIdx;
final rangeIds = context.state.displayOrder.sublist(minIdx, maxIdx + 1);
selectedRows.addAll(rangeIds);
return context.state.copyWith(
selection: context.state.selection.copyWith(selectedRowIds: selectedRows),
);
}