Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard pushes the content up / resizes the screen

Edit:

I got a report that this is a duplicate of When the keyboard appears, the Flutter widgets resize. How to prevent this?. While this is related, it is a different issue. I want the keyboard to overlap the UI until it reaches the TextField that has focus. This is default behavior on Android

Original:

I am an Android developer and just started with Flutter. I wanted to create a log in screen. I wanted an image above the TextField's. So I thought, I use a Stack to have the image on the background and some TextField's below.

The issue is that as soon as the keyboard appears, it pushes all content up. On Android, usually the keyboard only pushes up if necessary and only until it reaches the EditText.

I tried setting resizeToAvoidBottomPadding to false, but then nothing moves (of course) and the TextField's get covered by the keyboard.

I remember from playing around with iOS in the past, this is default behavior, maybe I should reconsider my layout?

At the moment, I wrap it in a ListView so that the user is able to scroll when the keyboard appears.

This is my layout (just for testing)

@override
Widget build(BuildContext context) {
  this.context = context;
  return new Scaffold(
      key: _scaffoldKey,
      body: new Stack(
          children: <Widget>[loginImage(), new Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[new TextField(), new TextField(),
        new TextField(), new TextField(),
        new TextField(), new TextField()],
      )])
  );
}

enter image description here: enter image description here

like image 304
Boy Avatar asked Apr 15 '18 08:04

Boy


People also ask

How do I stop my keyboard from overflowing my Flutter?

The solution to resolve this overflow error is to make your entire widget or in our case the Column scrollable. We can do that by wrapping our Column inside a SingleChildScrollView. Also, wrap the SingleChildScrollView with Center so that the entire UI is centered.

How do I make my keyboard height Flutter?

To know about the keyboard height, you can just check for the bottom property of viewInsets , when the keyboard is onscreen, this will hold the height of keyboard else zero. Note: The bottom property may have value even if some other system ui obscures the flutter ui from bottom. Hope that helps!

How do you turn off the behavior bottom navigation bar goes up with keyboard in Flutter?

bottomNavigationBar: isKeyboardOpen ? null : BottomAppBar(); This technique also works with the floating action bottom issue.. Save this answer.


2 Answers

I had this problem while setting autoFocus: true in a CupertinoTextField() and fixed it by setting resizeToAvoidBottomInset: false in Scaffold().

resizeToAvoidBottomPadding is deprecated now.

Use resizeToAvoidBottomInset.

like image 54
Hahnemann Avatar answered Sep 20 '22 13:09

Hahnemann


set this on scaffold:

1-resizeToAvoidBottomInset: true,

2-use stack to set your background.

body: Stack(fit: StackFit.expand, children: <Widget>[
          Opacity(
              opacity: 0.5,
              child: Image.asset('lib/assets/images/background3.jpg',
                  fit: BoxFit.cover)),
          Padding(
            padding: EdgeInsets.all(20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Header1(),
                SizedBox(
                  height: 10,
                ),
                Tittle("Welcome to Bitetat's live repots"),
                Expanded(
                  child: SingleChildScrollView(
                      physics: AlwaysScrollableScrollPhysics(),
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: <Widget>[
                          Container(

///// 3-there u can put ur fields

now you can enjoy nice back ground and your keyboard will not cover the fields and also scrollable.

like image 29
tina abdallah Avatar answered Sep 18 '22 13:09

tina abdallah