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) {
  final expandedGroups = Map<String, bool>.from(
    context.state.group.expandedGroups,
  );

  // Invert the *effective* state (isGroupExpanded defaults to false when
  // absent), not just the literal map entry — otherwise the first toggle
  // on a never-touched group would set it to `false` (a no-op, since
  // that's already the default) instead of visibly expanding it.
  expandedGroups[groupKey] = !context.state.group.isGroupExpanded(groupKey);

  return context.state.copyWith(
    group: context.state.group.copyWith(expandedGroups: expandedGroups),
  );
}