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

传入enum参数调用Dart函数报Conditions must have a static type of 'bool'错误如何解决

错误原因&修改方案

你遇到的报错是因为对应语言(Dart)语法中if判断的条件必须为布尔类型,你的代码共有3处需要调整:

  • if判断语句内误用了赋值运算符=,该操作的返回值是ButtonList枚举类型,不是布尔值,需要替换为判断相等的==运算符
  • 函数调用代码末尾多了1个多余的右括号,直接删除即可
  • 打印的字符串拼写有误,sucess修正为success

修改后完整代码

枚举定义(无需修改)

enum ButtonList {One, Two, Three}

函数调用代码

testFunc(ButtonList.Two);

函数实现代码

testFunc(ButtonList type) {
  if (type == ButtonList.Two) {
    print('success');
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 02:45:04