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
- Type 'Theme' does not satisfy the constr...
Type 'Theme' does not satisfy the constraint 'Row'. Type 'Theme' is missing the following properties from type 'Row': $id, $sequence, $tableId, $databaseId, a...
- client.ping() does not appear to work.
After upgrading to 1.8.0, I ran the `starter_for_flutter` and tested the ping. It failed with a "Server Error". I tried this again on my production instance (1...
- Is there any reason you cant use a manag...
So quick context I would like to host a selfhosted Appwrite instance and I personally prefer to use managed DBs when able and really like to keep my DBs on dedi...