I am using cloud_firestore and riverpod in my project.
I have a firestore database with some data. If I delete the data in firestore, I would expected my app to notice that as well. But at first I get the old data.
@riverpod
Option<MyObject> closeObjectLocation(CloseObjectLocationRef ref) {
final objects = ref.watch(objectsWithinRadiusProvider
.select((value) => value.valueOrNull));
debugPrint("objects count: ${objects?.length}");
}
The logs looks as follows:
objects count: null
objects count: 1
objects count: 0
It leads to wrong behaviours within the app.
There many layers between the provider and firestore.
@riverpod
Stream<List<Object>> objectsWithinRadius(ObjectsWithinRadiusRef
ref) {
final myLocation =
ref.watch(positionStreamProvider.select((value) =>
value.valueOrNull));
final objectsStream = ref
.watch(objectsWithinRadiusRepoProvider(
myLocation!.latitude, myLocation.longitude))
.getObjects();
return objectsStream;
}
Here the firestore stream.
Stream<List<DocumentSnapshot>> collectionStreamWithRadius({
required String path,
required double radius,
required String field,
required GeoFirePoint center,
}) {
return _streamErrorHandler(
() {
var reference = geoFlutterFire
.collection(collectionRef:
firebaseFirestore.collection(path))
.within(
center: center,
radius: radius,
field: field,
strictMode: true,
);
return reference;
},
);
}
Basically I want to invalidate the cache when I close the app such that it fetches new values gain and not the cache one.
2
Answers
well the solution was pretty easy, in hindsight. I just had to disable firestore offline support.
try this
i think the cuse is that as in start the stream is not passing any data, as the result variable is null.