我的要求是在列表 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
。这确实意味着您需要的那种布局。
这是有关如何使用GridView
的example:
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,
),
);
}),
);
这是一张显示GridView
和ListView
之间的布局差异的图片:关于flutter - 如何在flutter中并排对齐 ListView 中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63468731/