问题描述
我有几个文档ID,并且想在所有文档ID收集后运行一个函数。
I have several document id's and want to run a function after all of them are gathered.
现在我的代码如下:
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
在Cloud Firestore文档中,有一种名为 getAll( )
:
In Cloud Firestore documentation there is a method called getAll()
: https://cloud.google.com/nodejs/docs/reference/firestore/0.13.x/Firestore#getAll
<$ c是否有类似的东西$ c> Flutter SDK?如果不是,最好的方法是并行从服务器 get()
从服务器获取多个文档,并知道其所有承诺/未来
s已解决?
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?
推荐答案
仅服务器SDK提供getAll。当前没有等效的移动SDK。因为Flutter SDK只是Android和iOS SDK的包装,并且两者都不提供getAll,所以Flutter也没有提供它。现在,您只需要执行多次获取即可,这并不像听起来那样糟糕(所有请求都通过单个连接进行流水线处理。)
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).
Dart的资源,有关如何。这个问题不是Firestore特有的。
There are plenty of resources for Dart on how to wait for multiple futures. The issue is not unique to Firestore.
这篇关于Flutter中的Cloud Firestore getAll()等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!