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

Flutter中无法设置文字装饰颜色问题求助

问题解决:未定义命名参数'decorationColor'

你的代码存在语法括号错误,decorationColor被误放在了TextStyle构造函数的外部,变成了Text组件的参数,而Text组件并没有这个命名参数,因此触发错误。

修正后的代码如下:

Text(
  todo.todoText!,
  style: TextStyle(
    fontSize: 16,
    color: isDark ? Colors.white : Colors.black87,
    decoration: todo.isDone ? TextDecoration.lineThrough : null,
    decorationColor: isDark ? Colors.white : Colors.black87, // 现在属于TextStyle的参数
  ),
)

Flutter 3.16.9版本的TextStyle确实支持decorationColor参数,问题核心是你在decoration参数后提前闭合了TextStyle的花括号,导致后续参数归属错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 07:43:15