Flutter: I want my screen to automatically scroll up when selecting Textfield so that my submit button is not hidden?
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: (){},
),
Comments
-
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 over 3 yearsThanks 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 over 3 yearsremove this line:
resizeToAvoidBottomInset: false,
-
Damanjit Hundal over 3 yearsNice, that worked beautifully! Was using resizeToAvoidBottomInset before to not rebuild when keyboard shows up. Appreciate the assist!
-
Anton Molchan over 2 yearsThank you a lot! You save my time, I tried to find the same behavior more than a day