How to hide keyboard in Flutter

Keyboard is the most common UI widget in mobile apps. It can be used for taking input from users, and there are two main types of keyboards – soft keyboard and hard keyboard. The biggest difference between them is that a soft keyboard does not occupy space on screen like a hard one does. Instead, it appears only when user needs it and disappears when not needed.

Flutter provides high-quality support for both types of keyboard, however many apps only use soft keyboards. It is a good practice to hide a soft keyboard when user does not interact with it for some time, because currently Flutter has no way to find out if there are any changes in the text content coming from the input.

In this article, we will see how to handle keyboard hiding and show it again when user taps on an EditText widget or returns from another activity.

Working with TextField and Textformfield requires us to handle keyboard popup’s behavior. Dismissing it at the right time can smooth a user’s form input process.

We can hide the keyboard by 2 ways.

FocusScope.of(context).requestFocus(new FocusNode());
FocusScopeNode currentFocus = FocusScope.of(context);
FocusManager.instance.primaryFocus.unfocus();

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close