Reputation: 113
I use to have the package geoflutterfire2, I used this package to get the id of users that where in a certain distance from a specific location (latitude and longitude), my code was:
getSuppliersLocation(BuildContext context, int requestReach, String serviceCode,
double lat, double long) async {
final serviceRequest = Provider.of<CustomerRequest>(context, listen: false);
final user = firebaseAuth.currentUser?.uid;
final fcmToken = await firebaseMessaging.getToken();
late Stream<List<DocumentSnapshot>> stream;
late GeoFlutterFire geo;
geo = GeoFlutterFire();
final radius = requestReach / 1000;
String field = 'location';
String collectionRoute;
productionStatus
? collectionRoute = 'supplier'
: collectionRoute = 'Testsupplier';
var collectionReference = firestore
.collection(collectionRoute)
.where(serviceCode, isEqualTo: true)
.where('isActive', isEqualTo: true)
.where('isVerified', isEqualTo: true);
GeoFirePoint center = geo.point(latitude: lat, longitude: long);
stream = geo
.collection(collectionRef: collectionReference)
.within(center: center, radius: radius, field: field, strictMode: true);
controllerSuppliers = stream.listen((List<DocumentSnapshot> documentList) {
List<String> ids = [];
List<String> tokenIds = [];
List<String> phoneNumbers = [];
for (var item in documentList) {
final data = item.data() as Map<String, dynamic>;
if (data.containsKey('id') && data['id'] != user) {
ids.add(data['id']);
}
if (data.containsKey('tokenId') && data['tokenId'] != fcmToken) {
tokenIds.add(data['tokenId']);
}
if (data.containsKey('phoneNumber')) {
phoneNumbers.add(data['phoneNumber']);
}
}
if (ids.isNotEmpty) {
serviceRequest.setAuthorizedSuppliersIds = ids;
} else {}
serviceRequest.setAuthorizedSuppliersIds = ids;
serviceRequest.setAuthorizedSuppliersTokenIds = tokenIds;
serviceRequest.setAuthorizedSuppliersPhoneNumbers = phoneNumbers;
});
}
but I have to update to flutter 3.22, and with that my Google Sign In stop working, so I have to update the firebase_auth and firebase_core to avoid the Google Sign In problem, but when doing that, the geoflutterfire2 stop working, because it depends in an older firebase_auth and firebase_core package, geoflutterfire2 last update was 19 months ago, so I look for a new package and I found the Geoflutterfire_plus package, so I try to update my code but I'm blocked at this problem:
I need to make a query to get only the collection that meet this criteria:
var collectionReference = firestore
.collection(collectionRoute)
.where(serviceCode, isEqualTo: true)
.where('isActive', isEqualTo: true)
.where('isVerified', isEqualTo: true);
but the problem is that in order to do the stream:
Stream<List<DocumentSnapshot<Map<String, dynamic>>>> stream =
GeoCollectionReference<Map<String, dynamic>>(collectionReference).subscribeWithin(
center: center,
radiusInKm: radius,
field: field,
geopointFrom: geopointFrom);
the collectionReference needs to be CollectionReference<Map<String, dynamic>>, so the error is at this:
please help!!!
Upvotes: 1
Views: 101
Reputation: 1
If you're still struggling, this fork of GeoFlutterFire2 allows you to use a current rxdart so you can update other dependencies.
geoflutterfire2:
git: https://github.com/wilpar/GeoFlutterFire2-Firebase3
Upvotes: 0