【问题标题】:Flutter - remove space between items in ListViewFlutter - 删除ListView中项目之间的空间
【发布时间】:2019-03-26 17:28:10
【问题描述】:

我正在使用 ListView.builder 函数来创建项目列表。但是,iOS 中每个项目之间的空间很大(截图)。你知道如何删除项目吗?好像是默认的,因为我没有添加。

代码:

列表视图:

return Scaffold(
    body: ListView.builder(
          itemCount: data.length,
          itemBuilder: (context, index) {
            final model = data[index];
            if (model.path.isEmpty)
              return Divider(color: Colors.grey[500], indent: 40.0);
            else
              return ItemMenu(model.path, model.name);
          }),

);

项目:

return Row(
  crossAxisAlignment: CrossAxisAlignment.center,
  mainAxisAlignment: MainAxisAlignment.start,
  children: <Widget>[
    Image.asset(path, width: 100, height: 100,color: Colors.grey[500]),
    Text(name, style: MyTextTheme().getLightSmallGrey().copyWith(fontSize: 20.0, fontWeight: FontWeight.w700))
  ],
);

【问题讨论】:

  • height: 100 - 很可能会变小
  • 类似的问题已经解决了。 stackoverflow.com/questions/52441805/…
  • @VirenVVarasadiya 这是因为我没有使用 ListTile
  • @pskink 我想让图标保持那么大
  • 您的图像似乎有很多填充。您能否将其中一个图标附加到您的问题中?

标签: android ios flutter padding


【解决方案1】:

如果您使用 ListTile 小部件作为您的 ListView 项目,您可以添加 dense = true 选项:

ListView(
  children: [
    ListTile(
      dense: true,
      ...
    ),
    ListTile(
      dense: true,
      ...
    ),
  ]
),

【讨论】:

    【解决方案2】:

    我刚刚解决了这个问题,但在具有“适合”属性的图像网络中:Boxfit.cover/fill

    【讨论】: