call method

  1. @override
Future<void> call()
override

Implementation

@override
Future<void> call() async {
  final api = await apiFuture;
  final email = await emailFuture;
  final deviceId = await deviceIdFuture;
  final token = await tokenFuture;

  debugStatusNotifier.state =
      registerNotificationTokenEnabled ? null : 'Disabled';

  if (kDebugMode) {
    print('FCM Token: $token');
  }

  if (email == null || token == null || deviceId == null) return;

  if (!registerNotificationTokenEnabled) {
    if (kDebugMode) print('Registering notification tokens is disabled');
    return;
  }

  final mobileDevice = 'Platform: ${Platform.operatingSystem}, '
      'Version: ${Platform.operatingSystemVersion}';

  final result = await api.kemApiV3NotificationsTokenPost(
    body: RegisterNotificationV3Body(
      deviceId: deviceId,
      token: token,
      deviceDescription: mobileDevice,
      platform: PlatformDTO.firebasecloudmessagingv1,
      sendPushNotifications: true,
    ),
  );

  final debugStatusMessage = result.isSuccessful
      ? 'Token registration successful: ${result.statusCode}'
      : 'Token registration error: ${result.error}';

  debugStatusNotifier.state = debugStatusMessage;

  if (kDebugMode) {
    print(debugStatusMessage);
  }
}