Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase space between keyboard and TextField

I have several TextField and TextFormField in my app, but I customized them so they can display an error message below them.

Because it now shows an error, the space between the actual TextField seems smaller. So is there a way to increase the size between the keyboard and a widget when the screen scrolls up?

I'm assuming this space is a value set somewhere, but cannot seem to find it.

So this is not a question about making the screen scroll this works, it's about increasing the space between the keyboard.

Thanks.

like image 628
vixez Avatar asked Oct 17 '25 06:10

vixez


1 Answers

Since you make use of TextField widgets, you can use the scrollPadding property which indicates how much space you want to have between so called viewInsets (usually something like the UI keyboard) and the TextField widget. So you can set something like EdgeInsets.only(bottom: 32.0) (default is 20.0).

Keep in mind: This does only work, if the surrounding Scrollable (like ListView) has enough space to scroll past the TextField widget to fit the given scrollPadding - otherwise you will see, that the TextField is right above the keyboard, "ignoring" the padding. To resolve that, you could place a SizedBox as the last entry in your Scrollable widget which ensures that there is enough place to scroll once the keyboard is shown:

ListView(
  TextField(
    scrollPadding: const EdgeInsets.only(bottom: 32.0),
  ),
  SizedBox(height: MediaQuery.of(context).viewInsets.bottom + 32.0),
),
like image 187
kounex Avatar answered Oct 18 '25 21:10

kounex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!