Flutter - SingleChildScrollView placed at the top of the screen when keyboard pops up
Mobile Technologies
Mobile Computing
2 years ago
5
Star Rating
1
Rating
_x000D_
_x000D_
I want to make a simple screen that shows multiple TextFields in a Column, some content above and a button below. On my first attempt, without the SingleChildScrollView, I got an "renderflex overflowed" error which could be solved by placing the TextField within the SingeChildScrollView.
Now I have the problem that the SingleChildScrollView is placed way too high on my screen when I select any TextField and the keyboard pops up. I want it to stay basically just where it is since there is enough (yellow) room for the keyboard below the SingleChildScrollView.
This Gif shows how my app behaves.
This Gif shows the behavior that I would expect.
I tried applying code from the FlatApp-Flutter example to my app but was unable to find the part that actually fixes my issue.
Does anyone know how I can control how much the keyboard pushes the SingleChildScrollView up or how I can fix the issue? Thanks a lot.
Scaffold(
backgroundColor: Colors.yellow,
body: new SingleChildScrollView(
controller: _scrollController,
child: new Container(
margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),
color: Colors.orange,
child: new Column(children: [
new Container(
margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 20.0),
height: 200.0,
width: 200.0,
color: Colors.grey,
child: new Center(
child: Text("Show some stuff"),
),
),
new Container(
color: Colors.blue,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
new TextField(
decoration: InputDecoration(labelText: "Label 1"),
),
new TextField(
decoration: InputDecoration(labelText: "Label 2"),
),
],
),
),
new RaisedButton(
child: const Text('Start'),
color: Theme.of(context).accentColor,
textColor: Colors.white,
elevation: 4.0,
splashColor: Colors.blueGrey,
onPressed: () {
// Perform some action
//button1(context);
},
),
]),
)));
}
Posted on 16 Aug 2022, this text provides information on Mobile Computing related to Mobile Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.