android - Flutter - remove space between items in ListView
问题描述
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.
code:
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);
}),
);
Item:
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 项目,则可以添加 dense = true 选项:
ListView(
children: [
ListTile(
dense: true,
...
),
ListTile(
dense: true,
...
),
]
),
推荐阅读
- c# - 如何在 .NET Core 中执行多个任务,并检查哪些任务成功完成
- typescript - 是否可以在 Ionic 中“切片”模态?
- java - 这是从 Firebase 检索数据的正确方法吗?
- jupyter-notebook - pandoc 的 --webtex 的独立替代品
- google-maps - KML:将图标放在地标中而不是样式中
- r - R 和本地时间的 POSIXct 中缺少时区值
- c# - 在 TRX 结果文件中显示单元测试文件名
- java - SQS Java 客户端异常 - com.amazonaws.SdkClientException:无法执行 HTTP 请求:权限被拒绝:连接
- r - spread() 正在产生 NA 值。(R 编程)
- python - 在大型数据库上使用 smart_open 连接以使用 python 写入 s3