Geoflutterfire Query instead of CollectionReference error

482 views Asked by At

I have been updating my libraries and flutter version, where I got this error for Geoflutterfire. It says in the documentation that it is possible to use a Query instead of a CollectionReference. The Widget Geoflutterfire require a type of CollectionReference, which the query is use is not.

final geo = Geoflutterfire();
final center = geo.point(latitude: MyApp.userLocation.latitude!,longitude: MyApp.userLocation.longitude!);
FirebaseFirestore _firestore = FirebaseFirestore.instance;  
var queryRef = await _firestore
                .collection(COLLECTION_JOB)
                .where(IS_ACTIVE, isEqualTo: true)
                .where(IS_DELETED, isEqualTo: false);
    
 var stream = await geo
        .collection(collectionRef: queryRef)
        .within(center: center, radius: NEARBY_JOB_DISTANCE, field: GEO_HASH);

In the above code my collectionRef: queryRef won't run as I get this error: "The argument type 'Query<Map<String, dynamic>>' can't be assigned to the parameter type 'CollectionReference<Object?"

It is a simple problem and I tried to change the type to var instead of Query, where the code ran and gave me this error: "E/flutter (30258): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type '_JsonQuery' is not a subtype of type 'CollectionReference<Object?>' E/flutter (30258): #0 getGeoHashQuery (package:Hyree/data/firestore/queries.dart:33:34)"

I hope you can help me as the documentation says it is possible: https://github.com/awaik/GeoFlutterFire Under the chapter: Scale to Massive Collections

2

There are 2 answers

1
Frank van Puffelen On

From looking at the current reference documentation and code of the DarshanGowda0 / GeoFlutterFire library its collection method only accepts a CollectionReference and not a query.

It seems the documentation stating otherwise is wrong here, so you might want to file a bug for that.

0
ThitKho On

The answer is to downgrade the version of GeoFlutterFire to version 3.0.1 and Cloud Firestore to version 2.5.4.