consumeKeyboardToken method

  1. @override
bool consumeKeyboardToken()
override

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

@override
bool consumeKeyboardToken() {
  /// Prevents virtual keyboard from showing on first focus.
  /// Only for Android because on iOS when virtual keyboard is hidden then
  /// the onChange events on the InputField are not fired.
  /// Anyway it doesn't matter the keyboard to be shown because this feature
  /// is ued by the DataWedgeModes which depends on a external device which
  /// works as an external physical keyboard and then virtual keyboard
  /// will be hidden by default.

  if (PlatformUtils.isAndroid) {
    Future.delayed(const Duration(milliseconds: 10),
        () => SystemChannels.textInput.invokeMethod('TextInput.hide'));
  }
  return true;
}