我的应用程序页面仅由 a 组成,该页面Card
的Column
末尾是 a MaterialList
。即使我的列表只有一两个项目,卡片也会将其垂直空间扩展到屏幕底部,而不是停在列表项目的末尾。Column 文档表明这是正常的 Column 行为(“为每个子项布局一个空或零弹性因子(例如,那些未展开的弹性因子),具有无限的垂直约束”)。我认为将列表包装在 a 中Flexible
可能会达到我想要的效果,但是当我尝试时出现以下错误:
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter (11469): When a column is in a parent that does not provide a finite height constraint, for example if it is
I/flutter (11469): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (11469): flex on a child (e.g. using a Flexible) indicates that the child is to expand to fill the remaining
I/flutter (11469): space in the vertical direction.
I/flutter (11469): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter (11469): cannot simultaneously expand to fit its parent.
我显然误解了这种布局应该如何工作的东西。
这是我现在作为Scaffold
此页面正文的示例代码:
new Container(
// Outer container so we can set margins and padding for the cards
// that will hold the rest of the view.
alignment: FractionalOffset.topCenter,
margin: new EdgeInsets.only(top: style.wideMargin),
padding: new EdgeInsets.symmetric(horizontal: style.defaultMargin),
child: new Card(
child: new Column(
children: [
new CustomHeader(), // <-- a Row with some buttons in it
new Divider(),
new MaterialList(
type: MaterialListType.twoLine,
children: listItems, // <-- a list of custom Rows
),
],
),
),
)
我怎样才能拥有一张紧紧包裹着Column
小部件的卡片?