apply<T extends DataGridRow> method

  1. @override
Future<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
Future<DataGridState<T>?> apply<T extends DataGridRow>(
  EventContext<T> context,
) async {
  if (!context.state.rowsById.containsKey(rowId)) {
    return null;
  }

  final newRowsById = Map<double, T>.from(context.state.rowsById);
  newRowsById[rowId] = newRow as T;

  context.dataIndexer.setData(newRowsById);

  final filteredIds = context.state.filter.hasFilters
      ? await context.filterDelegate.applyFilters(
          rowsById: newRowsById,
          filters: context.state.filter.columnFilters.values.toList(),
          columns: context.state.columns,
        )
      : context.state.displayOrder;

  final sortedIds = context.state.sort.hasSort
      ? context.dataIndexer.sortIds(
          newRowsById,
          filteredIds,
          context.state.sort.sortColumn!,
          context.state.columns,
        )
      : filteredIds;

  return context.state.copyWith(
    rowsById: newRowsById,
    displayOrder: sortedIds,
  );
}