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

Flutter代码运行报错:Expected Identifier及Expected to find ":"问题求助

问题分析与修复

你的Flutter代码报错是因为三元运算符使用不完整。Dart的三元表达式要求必须包含 条件 ? 真值分支 : 假值分支 三个部分,你当前只写了条件为真时的TextDecoration.lineThrough,缺失了冒号:和条件为假时的分支,这才触发了编译错误。

修复后的代码示例:

child: Text(
  title,
  style: TextStyle(
    color: Colors.grey[700],
    decoration: _enabledMap[title] == true ? TextDecoration.lineThrough : TextDecoration.none
  ),
),

解释:当_enabledMap[title]为true时,文字添加删除线;否则保持无装饰(你也可以根据需求替换成其他TextDecoration值)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 17:27:21