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

Mobile Technologies Mobile Computing 2 years ago

8.59K 1 0 0 0

_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.

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.
0 views
0 shares

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.

Similar Forum


Q

Would Firebase be a good choice as a server for the Flutter mobile game I'm creating?

_x000D_ _x000D_ I am building a turn-based Flutter game. Would Firebase be a good choice as a server...
Q

Implement Bottom Navigation activity along with a VerticalViewPager with nested Cardview in Android...

_x000D_ _x000D_ I want to develop an Android App which will have a Bottom Navigation Bar and above i...
Q

(JS) For , determine if the device offers or not to capture a photo from the camera

_x000D_ _x000D_ When uploading a file, I need to give the user the possibility: upload the file fr...

Important Mobile Technologies Links