Flutter: When is a listener to a Firestore Document / Query activated


I am planning a new Flutter App using Cloud Firestore as a backend.
To make sure that the costs won’t explode, I want to be sure when my listeners are listening to changes.

When I use the following code to query through a collection, for example

  Stream<List<Message>> getMessages(String userUid) {
return _users // A Firestore Collection
    .map((snap) {
  return snap.documents
      .map((doc) => Message(doc.data['author'], doc.data['message']))

and using it in a StreamProvider as a parent of a screen / Scaffold. Does Flutter also listen to changes in the ‘messages’ collection when I am on another screen?


Nop it doesn’t listen as long as the screen isn’t mounted.

Answered By – samezedi

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *