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
相关产品推荐
相关产品推荐

