consumeKeyboardToken method

bool consumeKeyboardToken()

Removes the keyboard token from this focus node if it has one.

This mechanism helps distinguish between an input control gaining focus by default and gaining focus as a result of an explicit user action.

When a focus node requests the focus (either via FocusScopeNode.requestFocus or FocusScopeNode.autofocus), the focus node receives a keyboard token if it does not already have one. Later, when the focus node becomes focused, the widget that manages the TextInputConnection should show the keyboard (i.e. call TextInputConnection.show) only if it successfully consumes the keyboard token from the focus node.

Returns true if this method successfully consumes the keyboard token.

Implementation

bool consumeKeyboardToken() {
  if (!_hasKeyboardToken) {
    return false;
  }
  _hasKeyboardToken = false;
  return true;
}