keyboardDismiss static method

void keyboardDismiss(
  1. BuildContext context, {
  2. bool ifRemovesFocus = true,
})

Closes the keyboard. If ifRemovesFocus is true (the default) it also removes focus from whatever widget has it.

Implementation

static void keyboardDismiss(BuildContext context, {bool ifRemovesFocus = true}) {
  /// How to Dismiss the Keyboard in Flutter the Right Way.
  /// https://flutterigniter.com/dismiss-keyboard-form-lose-focus/

  if (ifRemovesFocus) FocusScope.of(context).requestFocus(FocusNode());
  SystemChannels.textInput.invokeMethod<dynamic>('TextInput.hide');
}