closeKeyBoard static method

void closeKeyBoard(
  1. BuildContext context, {
  2. FocusNode? focusNode,
})

Closes the on-screen keyboard by releasing focus.

Previously this also called SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive), which hid the status and navigation bars as a side effect of closing the keyboard. That system-UI manipulation has been removed; if the caller wants to hide system UI it should do so explicitly via SystemUtils.

Implementation

static void closeKeyBoard(BuildContext context, {FocusNode? focusNode}) {
  if (focusNode != null) {
    focusNode.unfocus();
  } else {
    FocusScope.of(context).unfocus();
  }
}