subscribe method

  1. @override
RealtimeSubscription subscribe(
  1. List<Object> channels, {
  2. List<String> queries = const [],
})

Subscribes to Appwrite events and returns a RealtimeSubscription object, which can be used to listen to events on the channels in realtime and to close the subscription to stop listening.

Possible channels are:

  • account
  • collections
  • collections.ID
  • collections.ID.documents
  • documents
  • documents.ID
  • files
  • files.ID
  • executions
  • executions.ID
  • functions.ID
  • teams
  • teams.ID
  • memberships
  • memberships.ID

The sample shows how you could use realtime to listen to changes in a collections.

final realtime = Realtime(client);
final subscription = realtime.subscribe(['collections']);
subscription.stream.listen((event) {
  print(event);
});

subscription.close();

You can also use Channel builders:

final subscription = realtime.subscribe([
  Channel.database('db').collection('col').document('doc').create(),
  Channel.bucket('bucket').file('file').update(),
  'account.*'
]);

Implementation

@override
RealtimeSubscription subscribe(
  List<Object> channels, {
  List<String> queries = const [],
}) {
  return subscribeTo(channels, queries);
}