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
相关产品推荐
相关产品推荐

