gpt4 book ai didi

input - Flutter - SingleChildScrollView 在键盘弹出时放置在屏幕顶部

转载 作者:IT王子 更新时间:2023-10-29 06:59:50 28 4
gpt4 key购买 nike

我想制作一个简单的屏幕,在一个列中显示多个 TextField,上面是一些内容,下面是一个按钮。在我的第一次尝试中,没有 SingleChildScrollView,我得到了一个“renderflex 溢出”错误,可以通过将 TextField 放在 SingeChildScrollView 中来解决。现在我遇到的问题是,当我选择任何 TextField 并弹出键盘时,SingleChildScrollView 在屏幕上的位置太高了。我希望它基本上保持在原来的位置,因为 SingleChildScrollView 下方有足够的(黄色)空间供键盘使用。 This Gif shows how my app behaves.

This Gif shows the behavior that I would expect.我尝试应用来自 FlatApp-Flutter example 的代码到我的应用程序,但无法找到真正解决我的问题的部分。有谁知道我如何控制键盘将 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);
},
),
]),
)));

最佳答案

我修好了。在实现我的导航时,我无意中将我的脚手架放在另一个脚手架的主体内,所以我的结构是这样的:

Scaffold(
appBar: AppBar(
title: Text('My App'),
),
body: ScaffoldShownInMyQuestion(),
)

只返回 SingleChildScrollView 而没有第二个脚手架环绕它并将其用作正文解决了我的问题。

关于input - Flutter - SingleChildScrollView 在键盘弹出时放置在屏幕顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52957344/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com