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/future
s are resolved?
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.