I'm writing an app to show nearby ATMs. I want to pass the collection refernce and i get this error.
Stream nearbyATM() async* {
GeoFirePoint point = geo.point(latitude: _position!.latitude, longitude: _position!.longitude);
final CollectionReference atms = _firestore.collection("atms");
double radius = 100;
String field = "location";
Stream<List<DocumentSnapshot>> stream = geo
.collection(collectionRef: atms)
.within(center: point, radius: radius, field: field);
}
To use the .within()
method with the GeoFlutterFire package, you need to pass a Query object as an argument to the GeoFireCollectionRef.collection() method.
You can directly use var query = _firestore.collection("atms").where(field, isLessThanOrEqualTo: point.distance, isGreaterThan: point.distance - radius);
to make the inference do it’s thing but If we can also define the Types implicitly as follows:
Stream nearbyATM() async* {
GeoFirePoint point = geo.point(latitude: _position!.latitude, longitude: _position!.longitude);
double radius = 100;
String field = "location";
// Let the Auto inference do it’s thing
Query<Map<String, dynamic>> query = _firestore.collection("atms").where(field, isLessThanOrEqualTo: point.distance, isGreaterThan: point.distance - radius);
// You can also
Stream<List<DocumentSnapshot>> stream = geo.collection(collectionRef: query).within(center: point, radius: radius, field: field);
}
We can pass Firebase Query to the collectionRef of geo.collection
not just CollectionRef of firestore only.
Reference : geoflutterfire.