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.
FocusScopeNode currentFocus = FocusScope.of(context); FocusManager.instance.primaryFocus.unfocus();