detach method

void detach()

Detaches the FocusNode this attachment point is associated with from the focus tree, and disconnects it from this attachment point.

Calling FocusNode.dispose will also automatically detach the node.

Implementation

void detach() {
  assert(_focusDebug(() => 'Detaching node:', () => <Object>[_node, 'With enclosing scope ${_node.enclosingScope}']));
  if (isAttached) {
    if (_node.hasPrimaryFocus || (_node._manager != null && _node._manager!._markedForFocus == _node)) {
      _node.unfocus(disposition: UnfocusDisposition.previouslyFocusedChild);
    }
    // This node is no longer in the tree, so shouldn't send notifications anymore.
    _node._manager?._markDetached(_node);
    _node._parent?._removeChild(_node);
    _node._attachment = null;
    assert(!_node.hasPrimaryFocus);
    assert(_node._manager?._markedForFocus != _node);
  }
  assert(!isAttached);
}