openCommonNotification static method

void openCommonNotification({
  1. required Map<String, dynamic> data,
  2. required String appToken,
  3. bool inBack = false,
})

Implementation

static void openCommonNotification(
    {required Map<String, dynamic> data,
    required String appToken,
    bool inBack = false}) async {
  if (InngageProperties.isInOpen) return;
  InngageProperties.isInOpen = true;
  Future.delayed(const Duration(seconds: 4))
      .then((value) => InngageProperties.isInOpen = false);

  if (InngageProperties.getDebugMode()) {
    debugPrint("openCommonNotification: $data");
  }

  //final Map<String, dynamic>? data = payload['data'];
  String? notificationId = '';

  if (data.containsKey('notId')) {
    notificationId = data['notId'];
  }
  Future.microtask(
    () => InngageProperties.inngageNetwork.notification(
      notid: notificationId ?? '',
      appToken: appToken,
    ),
  );
  final String type = data['type'] ?? '';
  final String url = data['url'] ?? '';

  final titleNotification = data['title'];
  final messageNotification = data['message'];

  if (type.isEmpty) {
    return;
  }
  switch (type) {
    case 'deep':
      if (!InngageProperties.blockDeepLink) {
        InngageUtils.launchURL(url);
      }

      return;
    case 'inapp':
      if (inBack) {
        Future.delayed(const Duration(seconds: 3))
            .then((value) => showCustomNotification(
                  messageNotification: messageNotification,
                  titleNotification: titleNotification,
                  url: url,
                ));
      } else {
        showCustomNotification(
          messageNotification: messageNotification,
          titleNotification: titleNotification,
          url: url,
        );
      }

      break;
  }
}