flutter - 假 || 假返回真
问题描述
(idController.text.isEmpty ||passwordController.text.isEmpty)
? () => {} :
() => {infoList[idController.text] = passwordController.text,
print(infoList[idController.text])}
我发现idController.text.isEmpty
两者passwordController.text.isEmpty
都是假的,因此结果应该是假的并且提前打印文本,但它什么都不做 - 意味着结果是真的。我找不到问题。
解决方案
当你做这样的事情
var myVar (idController.text.isEmpty ||passwordController.text.isEmpty)
? () {}
: () {...}
myVar
没有收到任何这些函数的执行结果,它正在接收函数本身。您没有执行它们,因此预计print
不会运行。
您的代码可能过于简化了您正在尝试做的事情。如果我从字面上理解,您不需要三元运算符。
if (!idController.text.isEmpty && !passwordController.text.isEmpty) {
...
}
推荐阅读
- ruby-on-rails - 包含的子查询上的 Active Record 选择字段
- azure - 使用 terraform 从规模集中删除实例
- ruby-on-rails - Rails NameError 'uninitialized constand User::Events' 使用设计
- php - 如何在 PHP 中多次运行脚本
- c# - 根据公共变量组合来自 2 个对象列表的值
- python - 在 Windows 10 中将标签添加到 python 文件
- node.js - 如何使用 PNPM 在两个节点项目之间共享 node_modules?
- python-3.x - 可执行文件立即以“NotImplementedError”关闭
- vue.js - 如何从所选选项的兄弟姐妹中获取值并将其作为输入字段自动填充(VueJS)中的值传递
- python - 对目录中的所有excel文件执行python脚本