Home > database >  Flutter Bottom of the screen to top of the keyboard
Flutter Bottom of the screen to top of the keyboard

Time:10-23

I have a ListView with a Login. If I get any error, it shows a snackbar. Currently, it is possible to fill out the Form because of the padding, but the Snackbar is hidden behind the keyboard. I want to avoid the Resize because I have a background as an Image, it looks strange when it gets resized. Any ideas how I should tell my ListView that the end of the screen is the top of the keyboard? Code:

resizeToAvoidBottomInset: false,

      body: Stack(children: [
        const Background(),
        ScrollConfiguration(
          behavior: MyBehavior(),
          child: ListView(

              controller: controllerV,
              scrollDirection: Axis.vertical,
              physics: isKeyboardVisible? const AlwaysScrollableScrollPhysics(): const NeverScrollableScrollPhysics(),

              children:    [

                  LoginForm(controllerH: widget.controllerH, controllerV: controllerV,),
                  RegisterForm(controllerV: controllerV,),
                Padding( // this is new
                    padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom)
                ),


              ]),
        ),
      ]),

or do you have an idea how I can prevent only the Picture from resizing? This would also fix my problem!

CodePudding user response:

Couldn't you just wrap the Stack containing the Background around the Scaffold instead of having it inside the Scaffold's body? eg..

 Stack(children: [
    const Background(),
    Scaffold(
      body: ScrollConfiguration(
        behavior: MyBehavior(),
        child: ListView(

CodePudding user response:

This will give you the height occupied by the keyboard. If you use it with the help of a Padding, this value increases when your keyboard is active and helps you to press the screen from the bottom.

MediaQuery.of(context).viewInsets.bottom
  • Related