颤振:检测键盘的打开/关闭 [英] Flutter: Detect keyboard open/close

查看:75
本文介绍了颤振:检测键盘的打开/关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的最顶层有一个 BottomNavigationBar 。我想检测基本上在应用程序/子树中任何地方的键盘打开/关闭状态,因此只要键盘可见,我就可以显示/隐藏 BottomNavigationBar

I have a BottomNavigationBar at the upper-most level of my app. I want to detect keyboard open/close basically anywhere in the app/subtree, so i can show/hide the BottomNavigationBar whenever the keyboard is visible.

这是一个普遍问题,可能与 BottomNavigationBar 没有直接关系。换句话说,从 BottomNavigationBar :-)

This is a general issue and may not be directly related to the BottomNavigationBar. In other words, abstract from the BottomNavigationBar :-)

推荐答案

To检查键盘的可见性,只需检查 viewInsets 属性在小部件树中的任何位置。当 viewInsets.bottom 等于零时,键盘被隐藏。

To check for keyboard visibility, just check for the viewInsets property anywhere in the widget tree. The keyboard is hidden when viewInsets.bottom is equal to zero.

您可以检查 viewInsets MediaQuery 相似:

MediaQuery.of(context).viewInsets.bottom

希望有帮助!

这篇关于颤振:检测键盘的打开/关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆