You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何调整ListView.Separated里ListTile的高度并移除上下多余空白

解决方案

ListTile自带默认的内边距和最小高度限制,你只需要调整ListTile的内置参数就能去掉多余空白,按需调整高度:

  • 调整contentPadding参数:默认自带上下内边距,你可以按需修改,甚至设为EdgeInsets.zero完全消除上下边距
  • 开启dense参数:设为true后会自动缩小ListTile的整体高度,更适合内容较少的列表场景
  • 调整minVerticalPadding参数:将值设为0可以移除ListTile默认的最小垂直内边距限制
  • 如果需要精准控制高度,直接给外层Container指定固定高度即可

修改后的代码示例:

Widget _LocationItem(LocationModel location) => Container(
      height: 48, // 可自定义需要的高度
      child: ListTile(
        dense: true,
        contentPadding: EdgeInsets.symmetric(horizontal: 16), // 仅保留左右边距,上下边距置0
        minVerticalPadding: 0,
        title: Text(location.name),
        trailing: Icon(Icons.arrow_right),
      ),
    );

如果觉得ListTile的布局约束太死,也可以直接自定义Row实现相同效果,灵活度更高:

Widget _LocationItem(LocationModel location) => Container(
      height: 48,
      padding: EdgeInsets.symmetric(horizontal: 16),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(location.name),
          Icon(Icons.arrow_right),
        ],
      ),
    );

内容的提问来源于stack exchange,提问作者Mike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 12:36:03