detach method Null safety

  1. @override
void detach()
override

Mark this node as detached.

Typically called only from the parent's detach, and by the owner to mark the root of a tree as detached.

Subclasses with children should override this method to first call their inherited detach method, and then detach all their children.

Implementations of this method should end with a call to the inherited method, as in super.detach().

Implementation

@override
void detach() {
  assert(owner!._nodes.containsKey(id));
  assert(!owner!._detachedNodes.contains(this));
  owner!._nodes.remove(id);
  owner!._detachedNodes.add(this);
  super.detach();
  assert(owner == null);
  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();
}