【发布时间】:2021-09-03 00:08:55
【问题描述】:
你们如何解决下面的 Flutter 布局?
我有一个屏幕,我必须在其中显示,如图所示:一个徽标 + 3 个 TextFormFields + 2 个按钮 + 一个容器。
问题:
- 我需要将所有小部件放在
Column中,并将列放在SingleChildScrollView中,这样当键盘弹出时,它不会覆盖TextFields。 - 最后一个小部件
Container将占用底部的所有剩余屏幕空间,但不会超过屏幕大小。为此,我的想法是使用Expanded小部件,以便 Container 可以扩展到屏幕底部,但这会报错:
The following assertion was thrown during performLayout(): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
所以我想我的问题,简而言之,我如何防止键盘覆盖 TextFields,同时我强制容器占用底部的所有剩余空间。
这是我的尝试:
SingleChildScrollView(
child: Column(
children: [
Image.asset("assets/images/appLogo.png"),
TextFormField(),
TextFormField(),
TextFormField(),
Row(children: [TextButton(), TextButton()]),
Expanded(child: Container())
],
));
【问题讨论】:
-
stackoverflow.com/questions/56326005/… 的副本以及解决此问题的多种方法
标签: flutter flutter-renderflex-error