Flutter 中的 Cloud Firestore getAll() 等效

ayt*_*nch 5 dart firebase flutter google-cloud-firestore

我有几个文档 ID,并希望在收集所有文档后运行一个函数。

现在我的代码是这样的:

    List<Future<DocumentSnapshot>> futures = [];
    currentVenuesIds.forEach((currentVenueId) {
      Future<DocumentSnapshot> venueFuture = Firestore.instance
          .collection('venues')
          .document(currentVenueId)
          .get();
      futures.add(venueFuture);
    });
    futures.getAll(...)   //????????? This does not exist
Run Code Online (Sandbox Code Playgroud)

在 Cloud Firestore 文档中有一种方法叫做getAll()https : //cloud.google.com/nodejs/docs/reference/firestore/0.13.x/Firestore#getAll

FlutterSDK有这样的东西吗?如果没有,get()以并行方式从服务器获取多个文档并知道它们的所有promise/futures 都已解析的最佳方法是什么?

Dou*_*son 5

只有服务器 SDK 提供 getAll。目前没有移动 SDK 的等效项。由于 Flutter SDK 只是 Android 和 iOS SDK 的包装器,并且它们都没有提供 getAll,因此 Flutter 也没有提供它。现在,您只需要执行多个获取,这并不像听起来那么糟糕(所有请求都通过单个连接进行流水线处理)。

Dart 有很多关于如何等待多个期货的资源。这个问题并不是 Firestore 独有的。