据了解,检查对象是null
还是Null
在Dart上应该是同一件事。
就像是:
print(bar == null);
print(bar is Null);
应该打印相同的值。但是,在使用Firebase的Flutter应用程序中,我得到了以下行为: print(snapshot.data['appearance']['details'].runtimeType); // Null
print(snapshot.data['appearance']['details'].runtimeType == null); // false
print(snapshot.data['appearance']['details'].runtimeType == Null); // true
print(snapshot.data['appearance']['details'].runtimeType is Null); // false
该字段的值是firebase上的null
。为什么会这样?
最佳答案
null
是一个值。 Null
是一种类型。.runtimeType
返回一个Type
。它不能返回null
值(这意味着该对象没有类型)。 null.runtimeType
返回Null
;也就是说,null
对象的类型为Null
。
至于.runtimeType is Null
为什么是false
的原因,请参见:What is the difference between 'is' and '==' in Dart?
关于firebase - Dart null与Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62978261/