【发布时间】:2021-07-11 00:24:47
【问题描述】:
我正在使用 Flutter 开发一个应用程序,例如送餐应用程序。所以我有餐厅应用程序和最终用户应用程序。
我现在在做什么
获取公司地址 (geoLocation),并使用带有 geohash 的 lat 和 lng 将位置存储在餐厅的 Firestore 集合中。对于最终用户应用,我正在获取当前设备位置。
我正在努力实现的目标
在最终用户应用上,我想创建一个列表,例如 uber Eats,使用最终用户设备的当前位置以及 Firestore 上的餐厅位置来显示附近的餐厅。
我正在使用 GeoFlutterFire 依赖项来获取位置。
我的功能
Stream nearbyComp() async* {
var pos = await location.getLocation();
GeoFirePoint point =
geo.point(latitude: pos.latitude, longitude: pos.longitude);
final CollectionReference users =
_firebaseFirestore.collection("Companies");
double radius = 10;
String field = 'location';
Stream<List<DocumentSnapshot>> stream = geo
.collection(collectionRef: users)
.within(center: point, radius: radius, field: field, strictMode: true);
yield stream;
}
我要在哪里显示列表
Container(
child: StreamBuilder(
stream: nearbyComp(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text("Loading");
}
return Container(
child: Text("companyName"), // This needs to be changed to a list? Display company name, image, etc, here.
);
},
),
),
当前问题
问题是,我找不到在最终用户屏幕上显示餐厅资料的方法,例如图像、名称等。我想我需要一个 ListView.Builder,但不知道该怎么做它与 nearComp() 函数上的 Stream 一起使用。
我的 Firestore
【问题讨论】:
标签: firebase flutter google-maps google-cloud-firestore geolocation