subscribe method

Future<UnsubscribeFunc> subscribe(
  1. String topic,
  2. RecordSubscriptionFunc callback, {
  3. String? expand,
  4. String? filter,
  5. String? fields,
  6. Map<String, dynamic> query = const {},
  7. Map<String, String> headers = const {},
})

Subscribe to realtime changes to the specified topic ("*" or record id).

If topic is the wildcard "*", then this method will subscribe to any record changes in the collection.

If topic is a record id, then this method will subscribe only to changes of the specified record id.

It's OK to subscribe multiple times to the same topic.

You can use the returned UnsubscribeFunc to remove the subscription. Or use unsubscribe(topic) if you want to remove all subscriptions attached to the topic.

Implementation

Future<UnsubscribeFunc> subscribe(
  String topic,
  RecordSubscriptionFunc callback, {
  String? expand,
  String? filter,
  String? fields,
  Map<String, dynamic> query = const {},
  Map<String, String> headers = const {},
}) {
  return client.realtime.subscribe(
    "$_collectionIdOrName/$topic",
    (e) {
      callback(RecordSubscriptionEvent.fromJson(e.jsonData()));
    },
    expand: expand,
    filter: filter,
    fields: fields,
    query: query,
    headers: headers,
  );
}