gpt4 book ai didi

flutter - ListView 正在扩大我的小部件的宽度

转载 作者:行者123 更新时间:2023-12-05 00:47:07 26 4
gpt4 key购买 nike

似乎 ListView 将其子项的宽度拉伸(stretch)到 100% 的屏幕宽度。

例如,尽管在下面的示例中明确设置了宽度,但宽度被拉伸(stretch)了。

ListView.builder(
shrinkWrap: true,
itemBuilder: (context, index) {
return SizedBox(
width: 120,
child: Container(
margin: EdgeInsets.all(10),
width: 100,
height: 200,
color: Colors.red),
);
},
itemCount: 3,
)

我避免此问题的唯一方法是将返回的小部件包装在 Row 中,但我希望尽可能避免这种情况(不想弄乱代码)。

最佳答案

只需将您的 SizedBox 包装在 AlignCenterUnconstrainedBox 小部件中。

在此处查看更多信息 布局行为 https://api.flutter.dev/flutter/widgets/Container-class.html

关于flutter - ListView 正在扩大我的小部件的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58101322/

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