Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lot of blank space on top of keyboard when keyboard is visible in Flutter TextField

Tags:

flutter

This is my code:

build(BuildContext context) {
  return new Scaffold(
    body: new SafeArea(
    child: new ListView.builder(
        itemBuilder: (itemBuilder),
      itemCount: (1),
      padding: kMaterialListPadding,
    ),
  )
 );
}
itemBuilder(BuildContext context, int index) {
    return new TextFormField(
        decoration: new InputDecoration(
          border: const OutlineInputBorder(),
          hintText: "What's on your mind?",
          helperText: "5-500 characters",
        ),
        maxLines: 3,
    );
}

When I tap on the text field, keyboard opens but lot of blank space appears on top of keyboard as you can see in the picture (border of textfield is cut).enter image description here

It happens because of the ListView. If I add just the text field to the body, appearance is fine.

like image 248
Gautham Avatar asked Mar 31 '18 04:03

Gautham


2 Answers

The reason for lot of wasted space was because there was a Scaffold inside a Scaffold. Each scaffold adding space for keyboard. Removing one solved the problem.

like image 131
Gautham Avatar answered Oct 21 '22 13:10

Gautham


Scaffold has a property resizeToAvoidBottomPadding. Set this property false

like image 35
user3255814 Avatar answered Oct 21 '22 14:10

user3255814