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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Edit ID of an existing collection
Hi there. Is it possible to edit an ID of an existing collection? Right now it looks impossible from AppWrite cloud at least.
- Current User is Not authorized
recreating same Thread