gpt4 book ai didi

flutter - 如何在flutter中并排对齐 ListView 中的项目?

转载 作者:行者123 更新时间:2023-12-03 03:20:34 25 4
gpt4 key购买 nike

我的要求是在列表 View 中安排以下项目:

item 1  item2
item 3 item4
item 5 item6
我目前正在使用ListView及其子级作为Wrap小部件(以在下一行中安排项目)
我的输出是这样的
item 1 item 4
item 2 item 5
item 3 item 6
如何在 flutter 打中达到我的要求

最佳答案

最好的方法是使用GridView。这确实意味着您需要的那种布局。
这是有关如何使用GridViewexample:

GridView.count(
// Create a grid with 2 columns. If you change the scrollDirection to
// horizontal, this produces 2 rows.
crossAxisCount: 2,
// Generate 100 widgets that display their index in the List.
children: List.generate(100, (index) {
return Center(
child: Text(
'Item $index',
style: Theme.of(context).textTheme.headline5,
),
);
}),
);
这是一张显示 GridViewListView之间的布局差异的图片:
enter image description here

关于flutter - 如何在flutter中并排对齐 ListView 中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63468731/

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