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

如何在Flutter ListTile中添加多元素并在leading与title间插图片?

解决ListTile在leading与title之间插入额外元素的问题

默认ListTile的leading、title、trailing属性仅能承载三个独立元素,要在leading和title之间插入图片,只需将title替换为包含图片与原文本的Row组件即可,具体修改代码如下:

return ListTile(
  tileColor: Colors.white,
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(10),
  ),
  leading: Icon(
    isSaved ? Icons.favorite : Icons.favorite_border,
    color: isSaved ? Colors.red : null,
  ),
  title: Row(
    mainAxisSize: MainAxisSize.min,
    children: [
      // 插入的图片组件,按需替换路径和尺寸
      Image.asset(
        'assets/your_image.png',
        width: 24,
        height: 24,
      ),
      SizedBox(width: 8), // 图片与标题文本的间距
      Text(nameData.getName(index)),
    ],
  ),
  trailing: Text(
    nameData.getDate(index),
  ),
);

补充说明:

  • ListTile的title属性支持传入任意Widget,用Row组合图片和原标题文本,就能实现leading之后先显示图片、再显示标题的布局。
  • 可根据需求调整图片尺寸、元素间距,或添加mainAxisAlignment等参数控制Row内元素的对齐方式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 16:40:38