showNotification method

Future<void> showNotification(
  1. RemoteMessage message
)

Implementation

Future<void> showNotification(RemoteMessage message) async {
  String? imageUrl = message.data['imageUrl'];
  String? largeIcon = message.data['largeIcon'];
  final bigPicturePath =
      await DownloadFile.downloadFile(imageUrl!, 'imageNotification');
  final largeIconPath =
      await DownloadFile.downloadFile(largeIcon!, 'largeIconNotification');

  // Create a style information object based on the image URL
  BigPictureStyleInformation? styleInformation;
  if (imageUrl != null || largeIcon != null) {
    styleInformation = BigPictureStyleInformation(
      contentTitle: 'overridden <b>big</b> content title',
      htmlFormatContentTitle: true,
      summaryText: 'summary <i>text</i>',
      htmlFormatSummaryText: true,
      FilePathAndroidBitmap(bigPicturePath),
      hideExpandedLargeIcon: true,
    );
  } else {
    styleInformation = null;
  }


  final Color notificationColor = Color(
      int.parse(message.data['color'].substring(1, 7), radix: 16) +
          0xFF000000);

  AndroidNotificationChannel channel = AndroidNotificationChannel(
    Random.secure().nextInt(1000).toString(),
    'High Importance Notification',
    description: 'This channel is used for important notifications.',
    importance: Importance.high,
  );

  await _flutterLocalNotificationsPlugin
      .resolvePlatformSpecificImplementation<
          AndroidFlutterLocalNotificationsPlugin>()
      ?.createNotificationChannel(channel);

  AndroidNotificationDetails androidNotificationDetails =
      AndroidNotificationDetails(
    channel.id.toString(),
    channel.name.toString(),
    icon: message.data['icon'] ?? '@mipmap/ic_launcher',
    channelDescription: "your channel description",
    importance: Importance.high,
    priority: Priority.high,
    ticker: "ticker",
    color: notificationColor,
    styleInformation: styleInformation,
    largeIcon: FilePathAndroidBitmap(largeIconPath),
    enableVibration: true,

  );

  const DarwinNotificationDetails darwinNotificationDetails =
      DarwinNotificationDetails(
    presentAlert: true,
    presentBadge: true,
    presentSound: true,
  );

  NotificationDetails notificationDetails = NotificationDetails(
    android: androidNotificationDetails,
    iOS: darwinNotificationDetails,
  );

  Future.delayed(Duration.zero, () {
    _flutterLocalNotificationsPlugin.show(
      0,
      message.notification?.title.toString(),
      message.notification?.body.toString(),
      notificationDetails,
      payload: message.data['screen'],
    );
  });
}