handleOnMessage static method

dynamic handleOnMessage({
  1. required AndroidNotificationChannelWrapperList channels,
})

Implementation

static handleOnMessage(
    {required AndroidNotificationChannelWrapperList channels}) {
  FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
    RemoteNotification? notification = message.notification;
    AndroidNotification? android = message.notification?.android;
    AppleNotification? apple = message.notification?.apple;
    // Android
    if (android != null) {
      if (notification != null) {
        if (channels.channels != null) {
          Future.forEach(channels.channels!,
              (AndroidNotificationChannelWrapper channel) async {
            if (channel.channel.id == android.channelId) {
              _flutterLocalNotificationsPlugin.show(
                  notification.hashCode,
                  notification.title,
                  notification.body,
                  NotificationDetails(
                    android: AndroidNotificationDetails(
                      channel.id,
                      channel.name,
                      icon: channel.icon,
                    ),
                  ));
              return;
            }
          });
        }

        _flutterLocalNotificationsPlugin.show(
            notification.hashCode,
            notification.title,
            notification.body,
            NotificationDetails(
              android: AndroidNotificationDetails(
                channels.defaultChannelId,
                channels.defaultChannelTitle,
                icon: channels.defaultIcon,
              ),
            ));
      }
      return;
    }

    // apple (iphone, ipad)
    if (apple != null) {
      _flutterLocalNotificationsPlugin.show(
          notification.hashCode,
          notification?.title,
          notification?.body,
          NotificationDetails(iOS: IOSNotificationDetails()));
      return;
    }
  });
}