Flutter/Firebase get documents by list of IDs using .get()

Viewed 804

This is a followup to Flutter Firebase get documents by array of IDs.

How would I get a Query of documents from a collection using a list of IDs? Let's says I have the following:

List<String> someList = ['abc123', 'def456', 'hij789']; // Need to query for these documentIDs

I'm using FieldPath.documentId() which works, but limits the query to 10.

Query query = Firestore.instance
    .collection(APIPath.products())
    .where(FieldPath.documentId(), whereIn: someList);

I would normally pass query to a function of mine that would return a Stream<List<Product>> as seen below.

return _service.queryStream(
  query: query,
  path: APIPath.products(),
  builder: (data) => Product.fromMap(data),
);

I know get() is a better option, but not sure what the code would look like if I wanted to return a Stream<List<Product>>.

0 Answers
Related