Rank 3: Container
how to subscribe collection
Votes
0
Replies
4
Participants
Unknown
Messages
5
Rank 3: Container
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
Rank 3: Container
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); } } }); } }
Rank 3: Container
main.dart
Rank 3: Container
.setEndpoint('https://cloud.appwrite.io/v1') .setProject('[PROJECT_ID]');
final realtime = Realtime(client);```