提问人:sonalika 提问时间:3/10/2023 更新时间:3/10/2023 访问量:44
一行中多种条件颤振 ||null 为 null 或 null 为字符串,如“null”
Multiple condition in one line flutter || null as a null or null as a String like "null"
问:
错误运算符 '||' 的操作数必须可分配给 'bool'。
hintText: _response?.Name.toString() != null || "null" ? _response?.Name.toString(): 'Enter Name',
在第二个条件之后,我在这一行中遇到了错误,实际上,问题是有时 null 是 == null,有时 null 是像“null”这样的字符串,所以我必须在提示文本中添加一个条件,如果 null 来自后端,则任何类型的 null 都不会显示在字符串上,所以它显示输入名称。
答:
0赞
krishnaacharyaa
3/10/2023
#1
改变
hintText: _response?.Name.toString() != null || "null" ? _response?.Name.toString(): 'Enter Name',
自
hintText: _response?.Name != null ? _response?.Name.toString(): 'Enter Name',
评论
|| "null" ?
这部分不是条件评估。您应该将其与某些东西相匹配,例如variable == null
'null'
null
response?.Name.toString() ?? 'Enter Name'