Search code examples
flutterflutter-layout

Textfield on Flutter dialog gives overflow on background


I'm having a problem using a textfield inside a dialog. When I click it, the keyboard and menu goes up and overflow my background. I could put a SingleChildScollView for that, but I want to keep proportional (I'm using Spacer with flex property to do that) distance between elements, so the scroll would break it.

Is there another way to stop the background overflow?

Below is my Code:

code for background

return Scaffold(
  body: Padding(
    padding: const EdgeInsets.symmetric(horizontal: 30.0),
    child: Column(
      children: [
        .
        . widgets with some spacers here
        .
      ],
    ),
  ),
);

code for dialog

showDialog(
context: context,
builder: (context) => StatefulBuilder(
  builder: (context, setState) {
    return SimpleDialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(8.0)),
      ),
      contentPadding: const EdgeInsets.fromLTRB(30.0, 15.0, 30.0, 15.0),
      children: [
        .
        . widgets here
        .
      ],
    );
  },
),

);

Images:

This is before clicking the textfield

this is right after I click the textfield


Solution

  • Add this resizeToAvoidBottomInset: false, under return Scaffold

    return Scaffold(
          resizeToAvoidBottomInset: false,   //new line
          body: Padding(
          ...
          ...