Flutter-删除ListView中项目之间的空间 [英] Flutter - remove space between items in ListView

查看:53
本文介绍了Flutter-删除ListView中项目之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ListView.builder函数创建项目列表.但是,iOS中每个项目之间的空间很大(屏幕截图).您知道如何删除物品吗?看来这是默认设置,因为我没有添加它.

I am using ListView.builder function to create a list of items. However, the space between each item in iOS is huge (screenshot). Do you know how to remove item? It seems it is by default, because I do not adding it.

代码:

ListView:

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))
  ],
);

推荐答案

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

If you are using a ListTile widgets as your ListView items, you can add the dense = true option:

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

这篇关于Flutter-删除ListView中项目之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆