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?
This widget will appear at the bottom of Search AppBar. Determines the Cloud Firestore collection You want to search in. Key for the firestore_collection value you want to search by. This function converts QuerySnapshot to A List of required data.
Fetching a sub-collection:To fetch orders subcollection we will need the documentId , so to get the documentId we need to fetch the users collection to get the userId . UserCard is a widget that displays the user details and on taping it new screen is pushed that contains all the orders of that particular user.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With