autofocus method

void autofocus (FocusNode node)

If this scope lacks a focus, request that the given node become the focus.

If the given node is not yet part of the focus tree, then add it as a child of this node.

Useful for widgets that wish to grab the focus if no other widget already has the focus.

The node is notified that it has received the primary focus in a microtask, so notification may lag the request by up to one frame.

Implementation

void autofocus(FocusNode node) {
  if (focusedChild == null) {
    if (node._parent == null) {
      _reparent(node);
    }
    assert(node.ancestors.contains(this),
      'Autofocus was requested for a node that is not a descendant of the scope from which it was requested.');
    node._doRequestFocus();
  }
}