dismissKeyboard static method

void dismissKeyboard(
  1. BuildContext context
)

DO THAT:

final FocusScopeNode focus = FocusScope.of(context);
if (!focus.hasPrimaryFocus) focus.requestFocus(FocusNode());

Implementation

static void dismissKeyboard(BuildContext context) {
  final FocusScopeNode focus = FocusScope.of(context);
  if (focus.hasFocus) {
    focus.unfocus();
  } else {
    focus.requestFocus(FocusNode());
  }
}