detach method

  1. @visibleForTesting
void detach()

Mark this node as detached from its owner.

Implementation

@visibleForTesting
void detach() {
  assert(_owner != null);
  assert(owner!._nodes.containsKey(id));
  assert(!owner!._detachedNodes.contains(this));
  owner!._nodes.remove(id);
  owner!._detachedNodes.add(this);

  // Clean up the according entry in owner._traversalParentNodes map.
  owner!._traversalParentNodes.removeWhere((Object key, SemanticsNode node) => node == this);
  // Clean up this node from the value set in owner._traversalChildNodes map.
  for (final Set<SemanticsNode> childSet in owner!._traversalChildNodes.values) {
    childSet.removeWhere((SemanticsNode node) => node == this);
  }

  _owner = null;
  assert(parent == null || attached == parent!.attached);
  if (_children != null) {
    for (final SemanticsNode child in _children!) {
      // The list of children may be stale and may contain nodes that have
      // been assigned to a different parent.
      if (child.parent == this) {
        child.detach();
      }
    }
  }
  // The other side will have forgotten this node if we ever send
  // it again, so make sure to mark it dirty so that it'll get
  // sent if it is resurrected.
  _markDirty();
}