想在 Flutter 的同一行添加多个项目

Want to add multiple items on the same line in Flutter

在下面的代码中,所有项目都显示在单独的一行中,即每个项目跨越整行。我如何更改代码以便多个项目可以出现在同一行?

提前致谢:)

Expanded(
  child: SizedBox(
    child: new ListView.builder(
      shrinkWrap: true,
      scrollDirection: Axis.vertical,
      itemCount: filterStatus == false
        ? allDeals.length
        : filteredDeals.length,
      itemBuilder: (BuildContext ctx, int index) {
        return Container(
          margin: EdgeInsets.only(top: 20.0),
          child: ListTile(...)
        );
      }
    ),
  ),
),

如果你想做这样的事情:

您可以使用 GridView.builder.

这是从屏幕截图构建示例的代码。

GridView.builder(
  gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
    maxCrossAxisExtent: 100, // the size of item
    crossAxisSpacing: 10, // margin of 10px top and bottom
    mainAxisSpacing: 10, // margin of 10px left and right
    // the spacing is not applicable on the GridView margins.
  ),
  itemCount: 30,
  itemBuilder: (_, index) {
    return Container(
      color: Colors.blue,
      child: Center(
        child: Text(
          'Item $index',
        ),
      ),
    );
  },
),