Cloud Firestore getAll() equivalent in Flutter

2019-08-21 10:53发布

I have several document id's and want to run a function after all of them are gathered.

Right now my code looks like this:

    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

In Cloud Firestore documentation there is a method called getAll(): https://cloud.google.com/nodejs/docs/reference/firestore/0.13.x/Firestore#getAll

Is there something like this for Flutter SDK? If not, what is the best way to get() multiple documents from the server in a parallel manner and know that all of their promise/futures are resolved?

1条回答
姐就是有狂的资本
2楼-- · 2019-08-21 11:40

Only the server SDKs offer getAll. There is currently no equivalent for the mobile SDKs. Since the Flutter SDK is just a wrapper around the Android and iOS SDKs, and neither of those offer getAll, so Flutter does not also offer it. Right now, you will just have to perform multiple gets, which is not as bad as it sounds (all requests are pipelined over a single connection).

There are plenty of resources for Dart on how to wait for multiple futures. The issue is not unique to Firestore.

查看更多
登录 后发表回答