reparentIfNeeded method

void reparentIfNeeded (FocusNode node)

Adopts the given node if it is focused in another scope.

A widget that requests that a node is focused should call this method during its build method in case the widget is moved from one location in the tree to another location that has a different focus scope.

Implementation

void reparentIfNeeded(FocusNode node) {
  assert(node != null);
  if (node._parent == null || node._parent == this)
    return;
  node.unfocus();
  assert(node._parent == null);
  if (_focus == null)
    _setFocus(node);
}