Patrick
Patrick

Reputation: 622

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
    .document(userUid)
    .collection('messages')
    .limit(20)
    .snapshots()
    .map((snap) {
  return snap.documents
      .map((doc) => Message(doc.data['author'], doc.data['message']))
      .toList();
});
}

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?

Upvotes: 1

Views: 248

Answers (1)

samezedi
samezedi

Reputation: 631

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

Upvotes: 3

Related Questions