gpt4 book ai didi

listview - 无法将水平滚动的 ListView 包装在列中

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

我正在尝试在 Flutter 中创建以下 UI。

enter image description here

这是我的代码的样子和相应的输出。

body: new Column(
children: <Widget>[
getTabs(),
new Container(
child: Expanded(
child: new ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 10,
itemBuilder: (context, index) => new Container(
alignment: Alignment.topCenter,
child: new Stack(
alignment: Alignment.topCenter,
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(8.0),
child: new Container(
width: 60.0,
height: 60.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new NetworkImage(
"https://pbs.twimg.com/profile_images/916384996092448768/PF1TSFOE_400x400.jpg")),
),
//margin: const EdgeInsets.symmetric(horizontal: 8.0),
),
),
index == 0
? Positioned(
right: 10.0,
bottom: 10.0,
child: new CircleAvatar(
backgroundColor: Colors.blueAccent,
radius: 10.0,
child: new Icon(
Icons.add,
size: 14.0,
color: Colors.white,
),
))
: new Container()
],
),
),

),
),
),
],
)

这是我在这段代码运行后得到的结果。

enter image description here

列表工作正常。我什至可以滚动它,但是一旦我尝试将它包装在一列中,就会出现错误。我想将它包装在一个列中,这样我就可以在列表之前添加一些小部件。我不能将它包装在任何其他小部件中。如果我可以将此 ListView 包装在一张卡片中,那将是有意义的。我错过了什么吗?

The following assertion was thrown during performLayout():
RenderFlex children have non-zero flex but incoming height constraints are unbounded. When a column is in a parent that does not provide a finite height constraint, for example, if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction. These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent. Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.

非常感谢任何帮助。

最佳答案

Expanded 放在包含 ListViewContainer 周围,而不是围绕 ListView 本身。

关于listview - 无法将水平滚动的 ListView 包装在列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50783743/

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