firebase - Dart null与Null

标签 firebase flutter dart

据了解,检查对象是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/

相关文章:

flutter - PageView.animateToPage 不适用于 elasticInOut 动画

android - 返回小部件时Future Builder不运行

dart - 强制变量只能被赋值一次

firebase - Flutter + Firebase。按时间顺序对数据进行排序

javascript - 如何获取写入Firebase的数据的Key/Id?

javascript - Firestore : cannot securely query data with a WHERE clause that uses both currentUser. uid 和 FieldPath.documentId()

android - flutter 如何通过打开对话框打开 txt 文件到特定页面?

java - 从 firebase 获取特定类别的数据

android - Flutter 为小于 21 的 SDK 启用 multiDex

dart - 为什么我们从服务器获取数据时需要使用异步?