我想将键盘设置为始终在聊天页面中打开,并且不应通过后退按钮将其关闭。
WillPopScope() 小部件仅阻止后退按钮导航回上一页,但仍会关闭键盘。我最初通过在文本表单字段中设置 autofocus = true 来打开键盘,所以我面临的唯一问题是防止键盘消失。
我在 Stack 中查看了多个问题,但找不到合适的解决方案来解决这个问题。我已经寻找答案两个多月了,希望有人能够帮助我解决这个问题。
更新:
我对设备高度进行了以下更改,其中减去了 MediaQuery.of(context).viewInsets.bottom,现在键盘的过渡更好了。
我意识到我之前尝试修复键盘并防止其被关闭的方法需要使用 Android 的 Java 或 Kotlin 在本机级别上完成太多修复。我最初想修复键盘,因为过渡很差,但通过以下方法,现在过渡更好,但仍有改进的空间。
var heightStatusBar = MediaQuery.of(context).padding.top;
var bottom = MediaQuery.of(context).viewInsets.bottom;
widthofdevice = MediaQuery.of(context).size.width;
heightofdevice =(MediaQuery.of(context).size.height) -
heightStatusBar - bottom;
Run Code Online (Sandbox Code Playgroud)