首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在flutter[firebase]中获取文档快照?

如何在flutter[firebase]中获取文档快照?
EN

Stack Overflow用户
提问于 2020-07-25 18:48:35
回答 1查看 274关注 0票数 0

我使用的是GeoFlutterFire,一个用来查询附近用户位置的软件包。

这是我的代码。

代码语言:javascript
复制
Future<Stream<List<DocumentSnapshot>>> getUsers() async { 
    GeoFirePoint center = geo.point(latitude: lat, longitude: long);
    var collectionref =  Firestore.instance.collection("locations");
    double radius = 50;
    String field = 'position';
    
    Stream<List<DocumentSnapshot>> stream = geo.collection(collectionRef: collectionref).within(center: center, radius: radius, field: field);
    stream.forEach((element) {print(element);});
}

我正在把这个打印到我的控制台上

代码语言:javascript
复制
[Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot'] 

我什么都试过了,都没结果。我还尝试从函数中返回Stream,但没有成功。请帮帮忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-25 20:26:58

尝试以下操作:

代码语言:javascript
复制
  Stream<List<DocumentSnapshot>> getUsers() async* {
    GeoFirePoint center = geo.point(latitude: lat, longitude: long);
    var collectionref = Firestore.instance.collection("locations");
    double radius = 50;
    String field = 'position';
    yield* geo
        .collection(collectionRef: collectionref)
        .within(center: center, radius: radius, field: field);
  }

使用async*可以返回一个Stream,然后可以使用yield*返回值,如果要在build()方法中使用此函数,则可以使用StreamBuilder小部件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63087399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档