unsubscribe method

bool unsubscribe()

Unsubscribe from this query result. It returns immediately without waiting for synchronization.

If the subscription is unnamed, the subscription matching the query will be removed. Return false if the RealmResults is not created by subscribe.

{@category Sync}

Implementation

bool unsubscribe() {
  bool unsubscribed = false;
  if (realm.config is! FlexibleSyncConfiguration) {
    throw RealmError('unsubscribe is only allowed on Realms opened with a FlexibleSyncConfiguration');
  }
  if (this is _SubscribedRealmResult<T>) {
    final subscriptionName = (this as _SubscribedRealmResult<T>).subscriptionName;
    realm.subscriptions.update((mutableSubscriptions) {
      if (subscriptionName != null) {
        unsubscribed = mutableSubscriptions.removeByName(subscriptionName);
      } else {
        unsubscribed = mutableSubscriptions.removeByQuery(this);
      }
    });
  }
  return unsubscribed;
}