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:
viewInsets.bottom determines the parts of the display that are completely obscured by system UI, typically by the device’s keyboard.
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!
Don’t stop, until you are breathing!💙
- Abhishek Doshi