detach method Null safety

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.


void detach() {
  assert(_node != null);
  assert(_focusDebug('Detaching node:', <String>[_node.toString(), '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._attachment = null;
    assert(_node._manager?._markedForFocus != _node);