Skip to content

Listen Collections

Efra Espada edited this page Feb 22, 2024 · 1 revision
chatsCollection.listen<Chat>(
  results: (Map<String, Chat> chats) async {
    state.chats = chats;
    refresh();
  },
);

This code sets up a listener on the chatsCollection collection. Whenever there are changes to the documents in the collection, the provided callback function results will be invoked with a map containing the updated documents.

You can control the listening behavior:

To temporarily pause listening for updates, you can call:

chatsCollection.pause();

To resume listening after pausing, you can call:

chatsCollection.resume();

To completely stop listening to updates, you can call:

await chatsCollection.cancel();

These methods allow you to manage the listening state of the collection according to your application's needs.