Keyboard Visibility — Flutter!

Abhishek Doshi
2 min readAug 27, 2021

Do you wish to check whether the user’s keyboard is visible or not? Let’s see how you can do that without using any packages!

Many times we have scenarios where we need to check whether the keyboard is visible or not. Maybe we want to change UI based on keyboard visibility or want to perform some functionality!

One of the ways is definitely to use any packages like flutter_keyboard_visibility, flutter_keyboard_size, keyboard_service, and many more are available. But, to use a package for such a simple functionality is not a good idea! Then how can we check whether the keyboard is open/visible on the screen?

We have a simple solution for this directly available in Flutter SDK!

To check whether the keyboard is open or not, we can use the following:

MediaQuery.of(context).viewInsets.bottom

viewInsets.bottom determines the parts of the display that are completely obscured by system UI, typically by the device’s keyboard.

So, if MediaQuery.of(context).viewInsets.bottom == 0.0 then the keyboard is closed.

Though this is a simple and short article, many might not know about this and it becomes handy to use! Now you can use this to define your UI or functionality!

Hope you enjoyed this article!

If you loved it, you can Buy Me A Coffee!

Don’t forget to connect with me on:

Don’t stop, until you are breathing!💙
- Abhishek Doshi

--

--

Abhishek Doshi

Google Developer Expert — Dart, Flutter & Firebase 💙💛