addNode method

void addNode(
  1. String nodeId
)

Adds a node to the explicit membership.

Only valid for GroupBehavior.explicit and GroupBehavior.parent. For GroupBehavior.bounds, use spatial containment instead.

If the added node is a GroupNode, its z-index is automatically bumped to ensure it renders above this parent group.

Implementation

void addNode(String nodeId) {
  assert(
    behavior != GroupBehavior.bounds,
    'Cannot add nodes to bounds behavior - use spatial containment',
  );
  runInAction(() {
    _nodeIds.add(nodeId);

    // Ensure nested groups have higher z-index than this parent
    if (groupContext != null) {
      final childNode = groupContext!.getNode(nodeId);
      if (childNode is GroupNode<T> &&
          childNode.zIndex.value <= zIndex.value) {
        childNode.zIndex.value = zIndex.value + 1;
      }
    }
  });
}