Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream doesn't update properly #175

Open
andidago opened this issue Feb 4, 2022 · 1 comment
Open

Stream doesn't update properly #175

andidago opened this issue Feb 4, 2022 · 1 comment

Comments

@andidago
Copy link

andidago commented Feb 4, 2022

Hello,

first of all thanks for the nice package!

My problem is that the stream doesn't update when my cloud function changes a field in a document eg("isViewed": true/false)
If however the document is updated by a flutter .update({"isViewed": true/false}) function, then the stream updates properly.

Here is my code:

  void getTaxiStream() async {
    final geo = Geoflutterfire();
    String field = 'location';

    //Get the max radius from my Firebase config document
    DocumentSnapshot<Map<String, dynamic>> radiusGetter = await FirebaseFirestore.instance.collection('config').doc('searchParams').get();
    maxRadius = radiusGetter.get('radius').toDouble();

    GeoFirePoint center = geo.point(latitude: widget.startPlace.coords.latitude, longitude: widget.startPlace.coords.longitude);
    var collectionReference = FirebaseFirestore.instance
        .collection('driver')
        .where('status', isEqualTo: 'ready')
        .where('isViewed', isEqualTo: false);

    //checking if a Listener is already running
    if(taxiListener == null) {
      Stream<List<DocumentSnapshot>> stream = geo
          .collection(collectionRef: collectionReference)
          .within(center: center, radius: maxRadius, field: field, strictMode: false);

      taxiListener = stream.listen((avblDriver) {
        //MY_CODE
      });
    } else {
      getTaxiList(nearestDriver);
    }
  }

Here is a snip of my Firestore:
example

I hope someone can help me with this problem. Since it is hard to explain on github, it would also be possible for me to meet on discord for further explanation.

Cheers Andre

@mcorrigan
Copy link

@andidago This seems like a question about Flutter and Firebase then it is about GeoFlutter. Take a look at this example in the FireFlutter project to see how to handle updates based on database changes on the server:

https://firebase.flutter.dev/docs/firestore/example

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants