42

I face a problem by wrapping TextField with new Expanded(). When try to search something in textfield its show me bottom overflow by 30px. Below is my code:

 Widget build(BuildContext context) {
    return new Scaffold(
        body:
      Column(
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              IconButton(icon: Icon(Icons.search), onPressed: () {
                setState(() {

                });
              }),
              new Flexible(
                child: new TextField(
                  onChanged: (String value) {
                    onchange(value);
                  },
                  maxLines: 1,
                  autocorrect: true,
//                  decoration: const InputDecoration(helperText: "Search"),
                  style: new TextStyle(fontSize: 10.0, color: Colors.black),
                ),
              ),
              _text != null ? IconButton(
                  icon: Icon(Icons.close), onPressed: (){
              }) : new Container(),

              IconButton(icon: Icon(Icons.bookmark_border), onPressed: () {}),
            ],
          ),
          new Expanded(
              child: FilstList(searchtext: _text,)
          ),


        ],
      ),
    );
  }
}
AAEM
  • 1,837
  • 2
  • 18
  • 26
Hitanshu Gogoi
  • 957
  • 3
  • 15
  • 24

10 Answers10

97

There are two solutions to this problem.

  1. Add resizeToAvoidBottomPadding: false to your Scaffold

    Scaffold(
     resizeToAvoidBottomPadding: false,
     body: ...)
    
  2. Put your FilstList(searchtext: _text,) inside a scrollableView (like SingleChildScrollView or ListView)
Dinesh Balasubramanian
  • 20,532
  • 7
  • 64
  • 57
  • 31
    `resizeToAvoidBottomPadding` is now [deprecated](https://api.flutter.dev/flutter/material/Scaffold/resizeToAvoidBottomPadding.html). Use `resizeToAvoidBottomInset: false` instead. – asherbret Oct 11 '19 at 19:33
  • 2
    This stopped the content of my body from being displayed. The body is a `TabBarView`. Each tab view has a dynamic height as it is populated with data from a server, so the views don't have a size available to them. Placing the `TabBarView` inside a fixed size `Container` reduces UI quality. – louisdeb Nov 18 '19 at 13:56
12

Use Scaffold property "resizeToAvoidBottomPadding: false" and "SingleChildScrollView" as parent of Scaffold body:

      home: Scaffold(
          resizeToAvoidBottomPadding: false,
          appBar: AppBar(
            title: Text("Registration Page"),
          ),
          body: SingleChildScrollView(
            child: RegisterUser(),
          )),

this will solve issue.

Dhanaji Yadav
  • 1,202
  • 1
  • 14
  • 22
8

You should use resizeToAvoidBottomInset

Scaffold(
  resizeToAvoidBottomInset: false, // set it to false
  ... 
)

If you're having issues with overflow error, use SingleChildScrollView with it.

Scaffold(
  resizeToAvoidBottomInset: false, // set it to false
  body: SingleChildScrollView(child: YourBody()),
)
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
4

I faced a similar problem and fixed it in the following way:

You can wrap it with SingleChildScrollView or with a ListView.

Scaffold(
    body: Container(
      height: MediaQuery.of(context).size.height * .50,
      child: SingleChildScrollView(
          child: Column( 
              ....
          )
      )
   )
 );
srijan439
  • 401
  • 5
  • 7
3

put resizeToAvoidBottomPadding as false in Scaffold:

  Scaffold(
    resizeToAvoidBottomPadding: false, 

update it is better solution: remove Column and put instead it ListView

because if you run this app on smaller device bottom items will disappear and hide from the show screen and that will be bad for App users.

abc
  • 28
  • 1
  • 11
Mahmoud Salah Eldin
  • 1,739
  • 16
  • 21
3

Use of resizeToAvoidBottomInset: false in your Scaffold is the best solution to that.

Innocent
  • 31
  • 2
0

Do two way

NO1.

Scaffold(
 resizeToAvoidBottomPadding: false, )

The problem is when you do this body content never gone top when you select input box..

Best practice

SingleChildScrollView widget

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
Musfiq Shanta
  • 1,298
  • 13
  • 9
0

Use CustomScrollView with SliverToBoxAdapter:

body: CustomScrollView( 
  slivers: [
     SliverToBoxAdapter(
         child: Form(....)
     ),
  ]
)
Hashem Aboonajmi
  • 13,077
  • 8
  • 66
  • 75
0

Use Scaffold and make "resizeToAvoidBottomInset" false.

 Scaffold(
            resizeToAvoidBottomInset: false,
            ........
   )
amit_roy
  • 1
  • 1
-1

Used SigleChildScrollView

sample code

Scaffold(
          appBar: //AppBar
          body: SingleChildScrollView(
            padding: EdgeInsets.symmetric(horizontal: 5.0, vertical: 3.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
user9139407
  • 964
  • 1
  • 12
  • 25