Using queryBuilder negates the values and returns empty
IncognitoGK9 opened this issue · 1 comments
If I pass a querybuilder to filter out values from the collection, the returns values are empty.
If I remove the query, values are returned. I need to return values based on the query:
var collectionReference =
FirebaseFirestore.instance.collection(Str.BODA_REGISTRATION_COLLECTION);
// .where(Str.UID, isNotEqualTo: FirebaseAuth.instance.currentUser!.uid); (this is not allowed, should be made to be allowed
double radiusInKm = 10;
String field = Str.GEOFIREPOINT_DATA;
GeoPoint geopointFrom(Map<String, dynamic> data) =>
(data[field] as Map<String, dynamic>)['geopoint'] as GeoPoint;
final Stream<List<DocumentSnapshot<Map<String, dynamic>>>> stream =
GeoCollectionReference<Map<String, dynamic>>(collectionReference)
.subscribeWithin(
center: center,
radiusInKm: radiusInKm,
field: field,
geopointFrom: geopointFrom,
//with the commented lines below, when uncommented, the list is empty, when commented, there are values. The data in firebase is to return all except for the one with a filter as shown.
// queryBuilder: (query) {
// return query
// .where(Str.UID,
// isNotEqualTo: FirebaseAuth.instance.currentUser!.uid)
// .orderBy(Str.UID)
// .orderBy(field);
// },
);
await for (List<DocumentSnapshot<Map<String, dynamic>>> bodaList
in stream) {
final distances = bodaList.map((boda) {
final bodaLocation = geopointFrom(boda.data()!);
final double distance =
center.distanceBetweenInKm(geopoint: bodaLocation);
return distance * 1000;
}).toList();
Possibly, have an updated documentation on how query filters work with GeoFlutterFire_plus with examples based on the approach I have up there. Or modify the package to include use of QuerySnapShot and show examples
Thank you for creating an issue!
As the comment below, it is not possible to use orderBy
in queryBuilder
because of the algorithm of geo query and restriction of Cloud Firestore. You can find the explanation in README as well.
https://github.com/KosukeSaigusa/geoflutterfire_plus#custom-query-conditions
Instead of using orderBy
, you can sort your query result in your client side.