Dart null/false/空检查:如何写这个更短? [英] Dart null / false / empty checking: How to write this shorter?

查看:12
本文介绍了Dart null/false/空检查:如何写这个更短?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我对除空字符串、null 和 false 之外的所有内容的 true 代码:

This is my code for true on everything but empty string, null and false:

if (routeinfo["no_route"] == "" || routeinfo["no_route"] == null || routeinfo["no_route"] == false) {
    // do sth ...
}

这是我对除空字符串、null、false 或零之外的所有内容的 true 代码:

This is my code for true on everything but empty string, null, false or zero:

if (routeinfo["no_route"] == "" || routeinfo["no_route"] == null || routeinfo["no_route"] == false || routeinfo["no_route"] == 0) {
    // do sth...
}

如何在 Dart 中写得更短?还是不可能?

How can I write this shorter in Dart? Or is it not possible?

推荐答案

你可以做到

if (["", null, false, 0].contains(routeinfo["no_route"])) {
  // do sth
}

这篇关于Dart null/false/空检查:如何写这个更短?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆