我可以在 flutter 的 **noSuchMethod()** 方法中使用什么参数来处理空快照数据?

What argument can I use inside the **noSuchMethod()** method in flutter to handle null snapshot data?

我有一个 AsyncSnapshot 存储来自 Future 方法的数据。最近发现返回的数据为null时要处理错误

以下代码片段中的 noSuchMethod() 方法中缺少什么参数?

      else if (snapshot.noSuchMethod(..missingArg..)){
          // Do something
      }

显然 noSuchMethod() 接受 Class Invocation

的参数类型

我认为您根本不需要致电 noSuchMethod。直接检查快照是否为 null 更具可读性和可理解性,因此请考虑将您的代码段更改为:

      else if (snapshot == null){
          // Do something
      }

您无需对 noSuchMethod() 执行任何操作。

您可以通过

检查快照是否没有数据
if(!snapshot.hasData) {
  // show loading indicator
}