
how to subscribe collection

You can, For example
import 'package:appwrite/appwrite.dart';
final client = Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('[PROJECT_ID]');
final realtime = Realtime(client);
final subscription = realtime.subscribe(['databases.DB_ID.collections.COLLECTION_ID.documents']);
subscription.stream.listen((response) {
// Callback will be executed on all account events.
print(response);
})
Replace DB_ID
with your database ID, and COLLECTION_ID
with your collection ID.
Read more here: https://appwrite.io/docs/realtime

Controller void suscribe(String postId) {
if (subscription == null) {
subscription = realtime.subscribe([
"databases.${AppWrite.dbId}.collections.${AppWrite.commentsCollectionId}.documents"
]);
subscription!.stream.listen((event) {
if (event.payload.isNotEmpty) {
CommentModel commentModel = CommentModel.fromJson(event.payload);
if (commentModel.postId == postId) {
commentsList.add(commentModel);
}
}
});
}
}

main.dart

.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('[PROJECT_ID]');
final realtime = Realtime(client);```
Recommended threads
- ❗[Help] Function stuck in "waiting" stat...
Hi Appwrite team 👋 I'm trying to contribute to Appwrite and followed the official setup instructions from the CONTRIBUTING.md guide to run the platform locall...
- Help with 409 Error on Relationship Setu...
I ran into a 409 document_already_exists issue. with AppWrite so I tried to debug. Here's what I've set up: Collection A has 3 attributes and a two-way 1-to-m...
- Database Double Requesting Error.
I am getting error for creating new document in an collection with new ID.unique() then too getting error of existing document. When button is pressed one docum...
