showNotification static method

Future<void> showNotification(
  1. RemoteMessage message,
  2. FlutterLocalNotificationsPlugin fln,
  3. bool data
)

Implementation

static Future<void> showNotification(RemoteMessage message,
    FlutterLocalNotificationsPlugin fln, bool data) async {
  String? image;
  String? title;
  String? body;

  NotificationBody notificationBody = convertNotification(message.data);

  if (Platform.isAndroid) {
    if (data) {
      title = notificationBody.growlytics!.title;
      body = notificationBody.growlytics!.message;
      if (notificationBody.growlytics != null &&
          notificationBody.growlytics!.media != null &&
          notificationBody.growlytics!.media!.image != null) {
        image = notificationBody.growlytics!.media!.image;
      } else {
        image = null;
      }
    } else {
      title = message.notification!.title;
      body = message.notification!.body;
      image = message.notification!.android!.imageUrl;
    }
  } else {
    if (data) {
      title = notificationBody.growlytics!.title;
      body = notificationBody.growlytics!.message;
      if (notificationBody.growlytics != null &&
          notificationBody.growlytics!.media != null &&
          notificationBody.growlytics!.media!.image != null) {
        image = notificationBody.growlytics!.media!.image;
      } else {
        image = null;
      }
    } else {
      title = message.notification!.title;
      body = message.notification!.body;
      image = message.notification!.apple!.imageUrl;
    }
  }
  if (image != null && image.isNotEmpty) {
    try {
      await showBigPictureNotificationHiddenLargeIcon(
          title, body, notificationBody, image, fln);
    } catch (e) {
      if (kDebugMode) {
        print(e.toString());
      }
      await showBigTextNotification(title, body!, notificationBody, fln);
    }
  } else {
    await showBigTextNotification(title, body!, notificationBody, fln);
  }
}