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
- Use Limits
I need urgent help, i use appwrite as a chat function for my website and my mobile android application, but recently, for the past 3 months, my database reaches...
- Method EQUAL not wrking in REST API Quer...
Request: ``` postman request 'https://nyc.cloud.appwrite.io/v1/tablesdb/{databaseId}/tables/{tableId}/rows?queries[]={%22method%22%3A%22select%22%2C%22values%2...
- 500 Internal Error when trying get to my...
When I click on my database row in the Cloud console, the page returns a **500 Internal Error** instead of opening the database dashboard. This completely block...