首页 > 解决方案 > 假 || 假返回真

问题描述

(idController.text.isEmpty ||passwordController.text.isEmpty)
? () => {} : 
() => {infoList[idController.text] = passwordController.text,
print(infoList[idController.text])}

我发现idController.text.isEmpty两者passwordController.text.isEmpty都是假的,因此结果应该是假的并且提前打印文本,但它什么都不做 - 意味着结果是真的。我找不到问题。

标签: flutterdart

解决方案


当你做这样的事情

var myVar (idController.text.isEmpty ||passwordController.text.isEmpty)
    ? () {} 
    : () {...}

myVar没有收到任何这些函数的执行结果,它正在接收函数本身。您没有执行它们,因此预计print不会运行。

您的代码可能过于简化了您正在尝试做的事情。如果我从字面上理解,您不需要三元运算符。

if (!idController.text.isEmpty && !passwordController.text.isEmpty) {
    ...
}

推荐阅读