Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Firestore getAll() equivalent in Flutter

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?

like image 215
aytunch Avatar asked Mar 01 '19 21:03

aytunch


People also ask

How do you search cloud firestore in flutter?

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.

How do you get Subcollection in firestore flutter?

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.


1 Answers

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.

like image 164
Doug Stevenson Avatar answered Nov 15 '22 09:11

Doug Stevenson