I have a Column of Expanded widgets like this:
return new Container(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Expanded(
flex: 1,
child: convertFrom,
),
new Expanded(
flex: 1,
child: convertTo,
),
new Expanded(
flex: 1,
child: description,
),
],
),
);
It looks like this:
convertFrom
, includes a TextField. When I tap on this text field, the Android keyboard appears on the screen. This changes the screen size, so the widgets resize like this:
Is there a way to have the keyboard "overlay" the screen so that my Column doesn't resize? If I don't use Expanded
widgets and hardcode a height for each widget, the widgets don't resize, but I get the black-and-yellow striped error when the keyboard appears (because there isn't enough space). This also isn't flexible for all screen sizes.
I'm not sure if this is an Android-specific or Flutter-specific.
Updated Answer
resizeToAvoidBottomPadding
is now deprecated.
The updated solution is to set resizeToAvoidBottomInset
property to false
.
Original Answer
In your Scaffold
, set resizeToAvoidBottomPadding
property to false
.
Most other answers suggest using resizeToAvoidBottomPadding=false
. In my experience this allows the keyboard to cover up text fields if they are underneath where the keyboard would appear.
My current solution is to force my column to be the same height as the screen, then place it in a SingleChildScrollView
so that Flutter automatically scrolls my screen up just enough when the keyboard is used.
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
minHeight: MediaQuery.of(context).size.height,
),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// CONTENT HERE
],
),
),
),
),
);
}
I use NeverScrollableScrollPhysics
so that the user cannot scroll around themselves.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With