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 i
When the keyboard opens, MediaQuery.of(context).viewInsets.bottom changes to reflect the new bottom (which is now at the top of the keyboard).
However, the Android app may be in fullscreen:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">true</item>
</style>
<color name="xxx">#FFFF00</color>
</resources>
When this is the case, viewInsets.bottom
will always be 0.0
, even when the keyboard is open,
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
In case of complicated widget tree MediaQuery.of(context).viewInsets.bottom gives null even if the keyboard is open. So, we have to mutate values down the tree.
This package gives simple in use provider for getting info down the tree https://pub.dev/packages/flutter_keyboard_size
Or, you can mutate info about keyboard size down the tree by yourselves (you can look the code in the package).