简体   繁体   English

Flutter listview 水平 + 换行

[英]Flutter listview horizontal + new line

I want to implement a horizontal listview in Flutter, but not scrollable.我想在 Flutter 中实现一个水平列表视图,但不能滚动。 I need it to continue on a new row when the space runs out in the horizontal direction.当空间在水平方向用完时,我需要它在新行上继续。 So far I've only got到目前为止我只有

 return ListView.separated(
                separatorBuilder: (BuildContext context, int index) =>
                    const Divider(),
                itemBuilder: (context, index) {
                  return ItemCard(items[index]);
                },
                scrollDirection: Axis.horizontal,
                itemCount: items.length);

In this case, you should try Wrap widget in flutter.在这种情况下,您应该尝试在颤振中包裹小部件。 By default, it will wrap in horizontal direction but if you want to wrap vertically then you can set direction.默认情况下,它会在水平方向环绕,但如果你想垂直环绕,那么你可以设置方向。

Wrap(
  direction: Axis.vertical,
  children: [
    MyWidget(),
    MyWidget(),
    MyWidget(),
    MyWidget(),
    MyWidget(),
  ],
),

With row and column, if there is not enough space then we get the yellow and black overflow warning.对于行和列,如果空间不足,则会收到黄色和黑色溢出警告。 But Wrap creates a new adjacent in the respective directive.但是 Wrap 在各自的指令中创建了一个新的相邻。 This will complete your list view requirement.这将完成您的列表视图要求。

There are many other options available which you can check here .您可以在此处查看许多其他选项。

set property physics in Listview.separated to make the listview not scrollable And also you need to set the width of the ItemCard() widget在 Listview.separated 中设置属性物理以使列表视图不可滚动而且您还需要设置 ItemCard() 小部件的宽度

return ListView.separated(physics: NeverScrollablePhysics(),

                separatorBuilder: (BuildContext context, int index) =>
                    const Divider(),
                itemBuilder: (context, index) {
                  return Container(
                    width: //your width size,
                    ItemCard(items[index])
                   );
                },
                scrollDirection: Axis.horizontal,
                itemCount: items.length);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM