adoptChild method

  1. @protected
  2. @mustCallSuper
void adoptChild(
  1. covariant AbstractNode child
)

Mark the given node as being a child of this node.

Subclasses should call this function when they acquire a new child.

Implementation

@protected
@mustCallSuper
void adoptChild(covariant AbstractNode child) {
  assert(child._parent == null);
  assert(() {
    AbstractNode node = this;
    while (node.parent != null) {
      node = node.parent!;
    }
    assert(node != child); // indicates we are about to create a cycle
    return true;
  }());
  child._parent = this;
  if (attached) {
    child.attach(_owner!);
  }
  redepthChild(child);
}