Flutter: I want my screen to automatically scroll up when selecting Textfield so that my submit button is not hidden?

481

Try with this code:

GlobalKey globalKey = GlobalKey();

...


TextField(
  onTap: ()async{
    await Future.delayed(Duration(milliseconds: 500));
    RenderObject object = globalKey.currentContext.findRenderObject();
    object.showOnScreen();
  },
), 
RaisedButton(
  key: globalKey,
  onPressed: (){},
),
Share:
481
Damanjit Hundal
Author by

Damanjit Hundal

Application developer who likes to farm.

Updated on December 24, 2022

Comments

  • Damanjit Hundal
    Damanjit Hundal over 1 year

    I'm currently wrapping my column widget in a SingleChildScrollView() and setting resizeToAvoidBototmInset: false on Scaffold(), yet the screen does not automatically scroll up when selecting the Textfields. Ideally, I want the submit button to show when user is inputting data into the second field. Currently it hides on some devices when the keyboard is visible.

    Scaffold(
        resizeToAvoidBottomInset: false,
        body: SingleChildScrollView(
            child: SafeArea(
                child: Stack(
                    children: <Widget> [
                        CustomPaint(),
                        Column(children: <Widget>[
                            TextField(), 
                            TextField(), 
                            RaisedButton(),
                        ])
                    ]
                )
            )
        )
    )
    

    This is what the current format looks like. I do not have a FocusNode() on the textfield and did think about raising the textfield based on when the keyboard is visible, but that disturbs my custom paint background and did not want to have that effect.

    From a conceptual point of view, is there something I'm missing that is preventing the screen from automatically scrolling up.

  • Damanjit Hundal
    Damanjit Hundal over 3 years
    Thanks for the reply, unfortunately this did not work. Didn't scroll the page up and the submit button is still hidden behind the keyboard.
  • Develocode 777
    Develocode 777 over 3 years
    remove this line: resizeToAvoidBottomInset: false,
  • Damanjit Hundal
    Damanjit Hundal over 3 years
    Nice, that worked beautifully! Was using resizeToAvoidBottomInset before to not rebuild when keyboard shows up. Appreciate the assist!
  • Anton Molchan
    Anton Molchan over 2 years
    Thank you a lot! You save my time, I tried to find the same behavior more than a day