Keyboard not being detected. MediaQuery.of(context).viewInsets.bottom always returns 0.0

我们两清 提交于 2019-12-21 19:55:38

问题


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.

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.

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)

回答1:


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>

Other way to remove fullscreen from the app is SystemChrome.setEnabledSystemUIOverlays([]) in flutter page.

One more thing you might want to check is resizeToAvoidBottomPadding: to false in Scaffold.

The issue has been raised in Flutter issues as well: https://github.com/flutter/flutter/issues/25050



来源:https://stackoverflow.com/questions/59197602/keyboard-not-being-detected-mediaquery-ofcontext-viewinsets-bottom-always-ret

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!