forgetChild method

  1. @protected
  2. @mustCallSuper
void forgetChild (
  1. Element child
)
@mustCallSuper, @protected, inherited

Remove the given child from the element's child list, in preparation for the child being reused elsewhere in the element tree.

This updates the child model such that, e.g., visitChildren does not walk that child anymore.

The element will still have a valid parent when this is called. After this is called, deactivateChild is called to sever the link to this object.

The update is responsible for updating or creating the new child that will replace this child.

Implementation

@protected
@mustCallSuper
void forgetChild(Element child) {
  // This method is called on the old parent when the given child (with a
  // global key) is given a new parent. We cannot remove the global key
  // reservation directly in this method because the forgotten child is not
  // removed from the tree until this Element is updated in [update]. If
  // [update] is never called, the forgotten child still represents a global
  // key duplication that we need to catch.
  assert(() {
    if (child.widget.key is GlobalKey)
      _debugForgottenChildrenWithGlobalKey.add(child);
    return true;
  }());
}