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

Flutter中如何防止ListTile的subtitle文本换行,实现单行显示

要实现ListTile的subtitle文本单行显示,只需为subtitle内部的Text组件添加单行截断配置即可,修改后的代码如下:

child: ListTile(
  leading: CircleAvatar(
    radius:20,
    backgroundColor: Colors.orange[200],
    child: Padding(
      padding: EdgeInsets.all(5),
      child: FittedBox(
        child: Text('\$100'),
      ),
    ),
  ),
  title: Text(widget.title),
  subtitle:Padding(
    padding: EdgeInsets.only(top: 10),
    child:Text(
      condimentList,
      style: TextStyle(color:Colors.grey),
      // 新增以下配置实现单行显示
      maxLines: 1,
      softWrap: false,
      overflow: TextOverflow.ellipsis,
    ),
  ),
  visualDensity: VisualDensity.compact,
  dense:true,
  trailing: ...
)

配置说明:

  • maxLines: 1:强制文本最多只渲染1行
  • softWrap: false:关闭文本自动换行逻辑
  • overflow: TextOverflow.ellipsis:超出显示宽度的文本末尾用省略号替代,可按需替换为TextOverflow.clip(直接裁剪超出内容)、TextOverflow.fade(超出内容淡出)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 20:18:02