unfocus method

  1. @override
void unfocus({
  1. UnfocusDisposition disposition = UnfocusDisposition.scope,
  2. bool showCursor = false,
})
override

Removes the focus on this node by moving the primary focus to another node.

This method removes focus from a node that has the primary focus, cancels any outstanding requests to focus it, while setting the primary focus to another node according to the disposition.

It is safe to call regardless of whether this node has ever requested focus or not. If this node doesn't have focus or primary focus, nothing happens.

The disposition argument determines which node will receive primary focus after this one loses it.

If disposition is set to UnfocusDisposition.scope (the default), then the previously focused node history of the enclosing scope will be cleared, and the primary focus will be moved to the nearest enclosing scope ancestor that is enabled for focus, ignoring the FocusScopeNode.focusedChild for that scope.

If disposition is set to UnfocusDisposition.previouslyFocusedChild, then this node will be removed from the previously focused list in the enclosingScope, and the focus will be moved to the previously focused node of the enclosingScope, which (if it is a scope itself), will find its focused child, etc., until a leaf focus node is found. If there is no previously focused child, then the scope itself will receive focus, as if UnfocusDisposition.scope were specified.

If you want this node to lose focus and the focus to move to the next or previous node in the enclosing FocusTraversalGroup, call nextFocus or previousFocus instead of calling unfocus.

{@tool dartpad} This example shows the difference between the different UnfocusDisposition values for unfocus.

Try setting focus on the four text fields by selecting them, and then select "UNFOCUS" to see what happens when the current FocusManager.primaryFocus is unfocused.

Try pressing the TAB key after unfocusing to see what the next widget chosen is.

** See code in examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart ** {@end-tool}

Implementation

@override
void unfocus({
  UnfocusDisposition disposition = UnfocusDisposition.scope,
  bool showCursor = false,
}) {
  keyboardToken = false;
  if (showCursor) {
    hideKeyboard();
  } else {
    super.unfocus(disposition: disposition);
  }
}