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

如何修改Flutter中TextDecoration删除线的颜色?

修改Flutter Text组件删除线颜色的方法

先看你给出的原始代码:

Text(
    text = "Told lee he'd be a millionaire",
    color = Color.White,
    textDecoration = TextDecoration.LineThrough
)

这段代码运行后,文字为白色,但删除线颜色会和文字颜色保持一致,无法单独区分。

你想要实现删除线与文字颜色不同的效果,在Flutter中可以通过TextStyle的decorationColor属性来实现,修改后的代码如下:

Text(
  "Told lee he'd be a millionaire",
  style: TextStyle(
    color: Colors.white,
    decoration: TextDecoration.lineThrough,
    decorationColor: Colors.red, // 自定义删除线颜色
    decorationStyle: TextDecorationStyle.solid, // 可选,设置删除线样式,比如实线、虚线等
  ),
)

核心逻辑:启用删除线的同时,通过decorationColor单独指定删除线的颜色,就能让文字和删除线呈现不同色彩,满足你的需求。

内容的提问来源于stack exchange,提问作者Kun.tito

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 20:48:20