
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
- I am receiving an Error 400 Invalid `suc...
Hi, I am an armature trying to set up a Google Sign-in button and authentication with some scopes. However, I don't understand why I can't redirect the button t...
- One-to-many relationship - way to quickl...
Title probably makes no sense - sorry. But I'm trying to create a database for buildings with units. Eight buildings each with eight units. So I made a buildin...
- Im getting this error when i try to crea...
SSLV3_ALERT_BAD_RECORD_MAC(tls_record.cc:583) error 268436476, uri=https://cloud.appwrite.io/v1/storage/buckets/67bxxxxxxxxxxxxd026/files (0) as well as this e...
