Search code examples
flutterdartlayoutkeyboard

Flutter - ShowModalBottomSheet does not go up when the keyboard comes out


I opened a new page through showModalBottomSheet. However, when you open the keyboard through textformfield, there is a phenomenon that the page does textformfield. I don't know what the problem is. Thank you so much for giving me a hint or an answer.

InkWell buildAddBtn() {
 return InkWell(
   child: Icon(
     Icons.add,
     size: 30.0,
  ),
  onTap: () {
    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      builder: (BuildContext context) => SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.only(
              bottom: MediaQuery.of(context).viewInsets.bottom),
          child: AddPage(logInUsr: usrEmail),
        ),
      ),
    );
  },
);
}

enter image description here

enter image description here


Solution

  • 1 create modalBottomSheet that take all height

    2 add Column with children

    1. Expanded with a listener to pop so our sheet will be at the bottom and also when user tap on an area on top of the sheet this still will trigger pop
    2. YourBottomSheet

    Example

    showModalBottomSheet(
          context: ctx,
          isScrollControlled: true,
          backgroundColor: Colors.transparent,
          builder: (ctx) => Container(
              height: double.infinity,
              width: double.infinity,
              color: Colors.transparent,
              child: Column(
                children: [
                  Expanded(
                    child: GestureDetector(
                      onTap: () => Navigator.of(context).pop(),
                      child: Container(
                        color: Colors.transparent,
                      ),
                    ),
                  ),
                  YourBottomSheet(),])));