unsetPushRegistration method

Future<void> unsetPushRegistration({
  1. Provider? provider,
  2. String? pushRegistrationId,
})

Unregisters a single mobile device, as one user can be connected to multiple mobile devices.

If the provider and pushRegistrationId parameters are not passed, it unregisters the default Firebase token for Android, or the default Apns token for iOS, for this device.

If passing parameters to this function, both provider and pushRegistrationId must not be null

Implementation

Future<void> unsetPushRegistration({
  Provider? provider,
  String? pushRegistrationId,
}) async {
  if ((provider == null && pushRegistrationId != null) ||
      (provider != null && pushRegistrationId == null)) {
    throw StateError('provider and pushRegistrationId must both be non-null');
  }

  if (_headlessWebView == null) {
    throw StateError(
        'The unsetPushRegistration method cannot be called after destroying the session');
  }

  if (!_completer.isCompleted) {
    if (_me == null) {
      throw StateError(
          'The me property needs to be set for the Session object before calling unsetPushRegistration');
    }

    if (kDebugMode) {
      print(
          '📗 session unsetPushRegistration: !_completer.isCompleted, awaiting for _completer.future');
    }
    await _completer.future;
  }

  if (kDebugMode) {
    print('📗 session unsetPushRegistration: Disabling push notifications');
  }

  if (provider == null && pushRegistrationId == null) {
    await _setOrUnsetPushRegistration(false);
  } else {
    await _executeAsync(
        'await session.unsetPushRegistration({provider: "${provider!.name}", pushRegistrationId: "$pushRegistrationId"});');
  }
}