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 focusedRowId = context.state.selection.focusedRowId;
if (focusedRowId == null) {
if (context.state.displayOrder.isEmpty) return null;
final firstRowId = context.state.displayOrder.first;
return context.state.copyWith(
selection: context.state.selection.copyWith(
focusedRowId: firstRowId,
selectedRowIds: {firstRowId},
),
);
}
final currentIndex = context.state.displayOrder.indexOf(focusedRowId);
if (currentIndex >= context.state.displayOrder.length - 1) return null;
final newRowId = context.state.displayOrder[currentIndex + 1];
return context.state.copyWith(
selection: context.state.selection.copyWith(
focusedRowId: newRowId,
selectedRowIds: {newRowId},
),
);
}