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

如何让Flutter内置ListTile在水平方向尽可能收缩?

让Flutter内置ListTile水平方向收缩至内容宽度

内置的ListTile默认会占满父容器的水平宽度,这是因为它内部的布局结构默认使用了MainAxisSize.max的Row。如果想让它像你自定义的ListTileShort那样尽可能收缩,不需要自己用Row模拟,可以通过以下两种简单方式实现:

方法1:用IntrinsicWidth包裹ListTile

IntrinsicWidth会强制子组件的宽度适应其内容的最小宽度,刚好符合需求:

IntrinsicWidth(
  child: ListTile(
    leading: Icon(Icons.account_circle),
    title: Text('仅收缩至内容宽度'),
    trailing: Icon(Icons.chevron_right),
  ),
)

方法2:用Wrap包裹ListTile

Wrap组件会让子组件只占用自身内容所需的空间,不会强制扩展到父容器宽度:

Wrap(
  children: [
    ListTile(
      leading: Icon(Icons.account_circle),
      title: Text('仅收缩至内容宽度'),
      trailing: Icon(Icons.chevron_right),
    ),
  ],
)

这两种方法都能让内置ListTile实现你想要的收缩效果,不需要重新造轮子。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 01:55:08