我有以下代码:
class _MyHomePageState extends State {
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return new Scaffold(
body: new Column(
children: [
new Container(
color: JBTheme.colorGreenBrand,
height: 130.0,
alignment: Alignment.bottomLeft,
child: new Center(
child: new Align(
alignment: Alignment.bottomCenter,
child: new Container(
color: JBTheme.colorOrange,
constraints: new BoxConstraints(maxWidth: 270.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Image.asset("flags/flag_dk.png"),
new Container(
margin: const EdgeInsets.only(top: 4.0, bottom: 4.0),
child: new Text("Danmark"),
),
new Text("DKK")
],
),
new Expanded(child: new Image.asset("images/arrow.png")),
new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Image.asset("flags/flag_us.png"),
new Container(
margin: const EdgeInsets.only(top: 4.0, bottom: 4.0),
child: new Text("USA"),
),
new Text("USD")
],
)
],
),
),
),
),
),
new Expanded(
child: new Container(
color: JBTheme.colorGreyMedium,
child: new Column(
children: [
new Expanded(child: new Container()),
new Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: new Card(
elevation: -8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: new Container(
width: 200.0,
height: 30.0,
color: JBTheme.colorWhite,
child: new Stack(
children: [
new TextField(
textAlign: TextAlign.center
)
],
)
),
)
)
],
),
)),
new Container(
height: 260.0,
color: JBTheme.colorGreenMint,
)
],
));
}
}
我没想到我的所有布局都会被全键盘高度向上移动,我希望它只能向上移动,以便聚焦的TextField可见(并且不会出错)。我该如何解决这个问题,为什么会发生这种情况?
谢谢 索伦
这是向我们展示在使用键盘时将从用户的视力中隐藏多少像素内容的Flutters方式。尝试将resizeToAvoidBottomPadding设置为false ...来自docs:
主体(和其他浮动小部件)是否应该自己调整大小以避免窗口的底部填充。
Scaffold(
resizeToAvoidBottomPadding: false,
这样可以避免调整大小,这样您至少可以避免显示dev警告。但请记住用户不会看到一些内容,这也是开发人员的警告。
这个问题有两种解决方案。
resizeToAvoidBottomPadding: false
添加到您的脚手架
Scaffold(
resizeToAvoidBottomPadding: false,
body: ...)
Scaffold body
放在一个scrollableView(如SingleChildScrollView或ListView)中
new Scaffold(
body: SingleChildScrollView(child: //your existing body
...)
你可以找到类似的问题并回答here