我希望制作一个简单的屏幕,其中包含多个TextField,以列的形式显示,上方有一些内容,下方有一个按钮。在第一次尝试时,没有使用SingleChildScrollView,结果出现了“renderflex overflowed”错误,将TextField放置在SingleChildScrollView中可以解决该问题。
现在我的问题是,当我选择任何TextField并弹出键盘时,SingleChildScrollView的位置太高了。我希望它基本保持在原地,因为在SingleChildScrollView下面有足够的(黄色)空间放置键盘。
此Gif显示我的应用程序的行为。
此Gif显示我期望的行为。
我尝试将FlatApp-Flutter示例中的代码应用到我的应用程序中,但无法找到实际解决我的问题的部分。
有人知道如何控制键盘推动SingleChildScrollView的量或如何解决这个问题吗?非常感谢。
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: <Widget>[
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: <Widget>[
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);
},
),
]),
)));
}
_scrollController
进行任何操作。 - Dinesh Balasubramanian