getNotificationData static method

Future<NotificationData> getNotificationData(
  1. dynamic rawData,
  2. String channel
)

Implementation

static Future<NotificationData> getNotificationData(
  dynamic rawData,
  String channel,
) async {
  try {
    final hasPermission =
        await NotificationHelper.checkAndRequestUserPermission();

    final messageId = rawData['data']?['message_id'];
    if (hasPermission) {
      NotificationHelper.sendNotificationStatus(messageId, 'delivered');
    } else {
      NotificationHelper.sendNotificationStatus(messageId, 'failed',
          failureReason: 'Permission Denied');
    }

    NotificationData notificationData;

    if (Platform.isAndroid) {
      final strategy = AndriodPushStrategy();
      notificationData = strategy.getNotificationData(rawData, channel);
    } else if (Platform.isIOS) {
      final strategy = ApplePushStrategy();
      notificationData = strategy.getNotificationData(rawData, channel);
    } else {
      throw UnsupportedError('Unsupported platform');
    }

    return notificationData;
  } catch (e) {
    rethrow;
  }
}