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

Flutter 如何让AnimatedList的滑动条目实现溢出内容隐藏?

解决方案

你需要使用ClipRect组件完成溢出内容的裁剪隐藏效果,修改方式如下:
在你编写_buildProgramDetailTile方法时,将返回的Slidable外层包裹一层ClipRect即可:

return ClipRect(
  child: Slidable(
    actionPane: SlidableDrawerActionPane(),
    secondaryActions: <Widget>[
      IconSlideAction(
        color: Colors.red,
        iconWidget: Icon(Icons.delete, size: 24),
        foregroundColor: Colors.white,
        onTap: () {
        },
      ),
    ],
    // 原有Slidable其余逻辑保持不变
    ...
  ),
);

如果是Tile内部的文字内容超出宽度需要隐藏,额外对文本组件做如下配置即可:

  • 文本组件外层用Expanded或Flexible包裹,限制文本最大可用宽度
  • 给文本组件设置溢出处理规则:
Row(
  children: [
    // 其余Tile内组件
    Expanded(
      child: Text(
        '长文本内容',
        overflow: TextOverflow.ellipsis, // 超出显示省略号,也可使用TextOverflow.clip直接裁剪
        maxLines: 1,
      ),
    )
  ],
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 23:15:07