How to avoid bottom overflow when keyboard open (in alert dialog)

Issue

In this screen i’m facing overflow every time I open keyboard in the alert text field. I already tried to put SingleChildScrollVIew in all the places and it didn’t resolve. This is the component which have the alertdialog:

Future<void> _showAlertDialog() async {
    return showDialog<void>(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Type the Name', textAlign: TextAlign.center,
            style: TextStyle(color: Colors.white)),
          content: TextField(
            controller: _nameController,
            keyboardType: TextInputType.text,
            textCapitalization: TextCapitalization.sentences,
          )
        );
      },
    );
  }

This is the build function:

Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TableCalendar(//default code),
            Divider(),
            _showList(),
          ],
        ),

      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add, color: Colors.white,),
        onPressed: () => _showCity(context) 
      ),
    );
  }

The _showAlertDialog is called inside _showCity (see build > floating action button > onpressed)

_showCity:

_showCity(BuildContext context){
  _showAlertDialog();
}

But after all attempts, every time I hit the textField in _showAlertDialog and it opens the keyboard, it throws an error:

A RenderFlex overflowed by 33 pixels on the bottom.

How can I handle that?

Update
_showList:

Widget _showList(){
    return ListView.builder(

        scrollDirection: Axis.vertical,
        shrinkWrap: true,
        itemCount: _sEv.length,
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
            onTap: () {
              
            },
            child: Dismissible(
              child: ListTile(
                leading: //loremipsum,
                title: //blablabla,
                subtitle: //dolorsit,
                ),
              ),
              key: UniqueKey(),
              direction: DismissDirection.startToEnd,
              background: Container(
                alignment: AlignmentDirectional.centerEnd,
                color: Colors.redAccent,
                child: Icon(Icons.delete_rounded),
              ),
              onDismissed: (DismissDirection direction) {
                setState(() {
                  //my irrelevant code
                });
            }
          ),);
        },
      );
  }

UPDATE 2
ScreenShot:
enter image description here

Solution

Just wrap the body of this page in SingleChildScrollView like this.

Widget build(BuildContext context) {
   return SingleChildScrollView(
      child: Scaffold(
         resizeToAvoidBottomPadding: false,
         body: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [ TableCalendar(
              //default code), 
              Divider(), _showList(),
            ],
         ),
         floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add, color: Colors.white,),
            onPressed: () => _showCity(context)
         ),
      ),
   );
}

Answered By – Usman Akhlaq

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *