toggleGroup method

void toggleGroup(
  1. String groupId
)

Toggle the expansion state of a group.

Implementation

void toggleGroup(String groupId) {
  final current = state;
  final isExpanded = current.expandedGroupIds.contains(groupId);

  if (isExpanded) {
    state = current.copyWith(
      expandedGroupIds:
          current.expandedGroupIds.where((id) => id != groupId).toList(),
    );
  } else {
    state = current.copyWith(
      expandedGroupIds: [...current.expandedGroupIds, groupId],
    );
  }
}