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

Flutter开发:ListView与首个ListTile之间存在间隙的问题

Flutter ListView 与首个 ListTile 间隙问题解决

你遇到的间隙是因为ListView组件默认带有顶部内边距,和调整Container尺寸、移除头部标题这些操作无关,直接用以下方法解决:

核心解决步骤

在ListView.builder里添加padding: EdgeInsets.zero,清除它的默认内边距即可:

ListView.builder(
  padding: EdgeInsets.zero, // 关键:清除ListView默认内边距
  itemBuilder: (BuildContext context, int index) {
    return Container(
      decoration: const BoxDecoration(
        border: Border(
          top: BorderSide(
            color: Colors.black,
            width: 0.6
          )
        )
      ),
      child: ListTile(
        title: Text(
          exercises[index],
          style: const TextStyle(
            fontSize: 22,
            color: Colors.white,
          ),
        ),
      ),
    );
  },
  itemCount: exercises.length,
)

如果之后仍存在细微间隙,可以检查ListTile的默认边距,通过contentPadding属性自定义调整,比如:

ListTile(
  contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 0), // 自定义内边距
  // ... 其他属性
)

内容的提问来源于stack exchange,提问作者Alexandre Carneiro da Silva

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 00:50:35