我使用的是GeoFlutterFire,一个用来查询附近用户位置的软件包。
这是我的代码。
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);});
}
我正在把这个打印到我的控制台上
[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
,但没有成功。请帮帮忙。
发布于 2020-07-25 12:26:58
尝试以下操作:
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
小部件。
https://stackoverflow.com/questions/63087399
复制