handleNotification method

Future<void> handleNotification(
  1. RemoteMessage message
)

Implementation

Future<void> handleNotification(RemoteMessage message) async {
  RemoteNotification? notification = message.notification;
  AndroidNotification? android = message.notification?.android;

  if (notification != null && android != null) {
    String msgId = message.data['px.msg_id'] ?? '';
    String title = message.data['px.title'] ?? notification.title ?? '';
    String body = message.data['px.body'] ?? notification.body ?? '';
    String? icon = message.data['px.icon'];

    // Send the delivered event to PushExpressManager
    PushExpressManager().sendNotificationEvent(
      msgId,
      Events.delivered,
    );

    File? imageFile;

    if (message.data['px.image'] != null ||
        notification.android?.imageUrl != null) {
      String imageUrl =
          message.data['px.image'] ?? notification.android?.imageUrl ?? '';
      imageFile = await _downloadImage(imageUrl);
    }

    if (imageFile != null) {
      _showNotification(
        msgId,
        title,
        body,
        icon,
        image: imageFile.path,
      );
      return;
    } else {
      _showNotification(msgId, title, body, icon);
    }
  }
}