问题描述
我有一个带有TextField的脚手架。以前,键盘会将字段移到键盘上方时,它始终会覆盖该字段。这在我项目的所有页面上都发生。
I have a scaffold with a TextField inside. The keyboard always covers this field when it previously would move the field above the keyboard. This is happening on all the pages in my project.
我已将MediaQuery.of(context).viewInsets.bottom添加到我的构建方法中,并且始终返回0.0。键盘抬起时,不会重建。我尝试将resizeToAvoidBottomInset设置为true和false,而没有进行任何更改。我尝试将其包装在Scrollable小部件中,没有任何变化。
I've added MediaQuery.of(context).viewInsets.bottom to my build method and it always returns 0.0. When the keyboard comes up there is no rebuild. I've tried settings resizeToAvoidBottomInset to true and false with no change. I've tried wrapping it in a Scrollable widget, no change.
在IOS上一切正常,这只会影响android的构建。
Everything works fine in IOS, this only affects android build.
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, v1.10.15, on Mac OS X 10.15.1 19B88, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
[✓] Android Studio
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.40.2)
[✓] Connected device (1 available)
推荐答案
我最近遇到了这个问题。您是否将全屏设置为true?如果启用了全屏,MediaQuery.viewInsets.bottom将返回0.0。由于您提到的问题仅在android中出现,因此有可能在本机android文件中设置了全屏属性。检查styles.xml
I've had this issue recently. Do you have fullscreen set to true? If fullscreen is enabled, MediaQuery.viewInsets.bottom will return 0.0. Since you mentioned the problem only occurs in android, It's possible you set the fullscreen property in the native android files. Check styles.xml
<item name="android:windowFullscreen">false</item>
从应用程序中删除全屏的其他方法是 SystemChrome.setEnabledSystemUIOverlays([] )
。
Other way to remove fullscreen from the app is SystemChrome.setEnabledSystemUIOverlays([])
in flutter page.
您可能要检查的另一件事是 resizeToAvoidBottomPadding:
One more thing you might want to check is resizeToAvoidBottomPadding:
to false in Scaffold.
在Flutter问题中也提出了这个问题:
The issue has been raised in Flutter issues as well: https://github.com/flutter/flutter/issues/25050
这篇关于未检测到键盘。 MediaQuery.of(context).viewInsets.bottom始终返回0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!