I have a screen in which I have a container with fixed width but unconstrained height. The contents of the container are hidden by the keyboard popup. I want to make the container scrollable or in focus when the keyboard popup is shown. Following is my code:
Scaffold(
backgroundColor: Colors.green, // Set the background color of the app
body: Center(
child: SingleChildScrollView(
child: Container(
width: 480,
padding: EdgeInsets.all(16.0),
color: Colors.white, // Set the background color of the container
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
decoration: InputDecoration(labelText: 'Field 1'),
),
SizedBox(height: 16.0), // Add spacing between fields
TextField(
decoration: InputDecoration(labelText: 'Field 2'),
),
SizedBox(height: 16.0),
TextField(
decoration: InputDecoration(labelText: 'Field 3'),
),
SizedBox(height: 16.0),
TextField(
decoration: InputDecoration(labelText: 'Field 4'),
),
SizedBox(height: 16.0),
TextField(
decoration: InputDecoration(labelText: 'Field 5'),
),
],
),
),
),
),
);
It only happens when the phone is in landscape view and I click on a textfield that brings the keyboard popup. I tried chatgtp and gemini but they both give the same answers that do not work. Kindly help. Currently it looks like this
2
Answers
Put your
Container
widget in aColumn
. Normally, I useSingleChildScrollView
andColumn
together.To make your container scrollable when the keyboard is displayed, you can use SingleChildScrollView in the body of a scaffold and ensure that your TextFields are handled correctly when the keyboard appears. You can also use MediaQuery to adjust the padding of SingleChildScrollView to account for the keyboard.