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) {
  if (context.state.selection.mode == SelectionMode.none) {
    return null;
  }

  final Set<double> visibleRowIds;

  if (rowIds != null) {
    visibleRowIds = rowIds!;
  } else {
    visibleRowIds = <double>{};
    final viewport = context.state.viewport;
    for (
      int i = viewport.firstVisibleRow;
      i <= viewport.lastVisibleRow && i < context.state.displayOrder.length;
      i++
    ) {
      visibleRowIds.add(context.state.displayOrder[i]);
    }
  }

  return context.state.copyWith(
    selection: context.state.selection.copyWith(
      selectedRowIds: visibleRowIds,
    ),
  );
}