myBackgroundMessageHandler function

Future myBackgroundMessageHandler(
  1. RemoteMessage message
)

Implementation

@pragma('vm:entry-point')
Future<dynamic> myBackgroundMessageHandler(RemoteMessage message) async {
  var androidInitialize =
      const AndroidInitializationSettings('notification_icon');
  var iOSInitialize = const DarwinInitializationSettings();

  var initializationsSettings =
      InitializationSettings(android: androidInitialize, iOS: iOSInitialize);

  flutterLocalNotificationsPlugin.initialize(initializationsSettings,
      onDidReceiveNotificationResponse: (NotificationResponse load) async {
    try {
      NotificationBody payload;
      if (load.payload!.isNotEmpty) {
        payload = NotificationBody.fromJson(jsonDecode(load.payload!));
      }
    } catch (_) {}
    return;
  });

  NotificationBody notificationBody =
      NotificationHelper.convertNotification(message.data);

  EventModel event = EventModel(
    name: Constants.received,
    eventTime: DateTime.now().millisecondsSinceEpoch,
    properties: jsonEncode(notificationBody.toJson()),
  );



  await DatabaseHelper().insertEvent(event);
  NotificationHelper.showNotification(
      message, flutterLocalNotificationsPlugin, true);
}