Flutter - SingleChildScrollView placed at the top of the screen when keyboard pops up

Mobile Technologies Mobile Computing 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

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.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ I fixed it. When implementing my navigation, I unintentionally placed my Scaffold inside the body of another Scaffold, so my structure was like this: Scaffold( appBar: AppBar( title: Text('My App'), ), body: ScaffoldShownInMyQuestion(), ) Returning just the SingleChildScrollView without the second Scaffold wrapping around it and using that as body fixed my problem.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Mobile Technologies Links