0

i would ask you how can i share silent data between pages using awesome_notifications_fcm package. i tried using eventBus to send and listen new data inside mySilentDataHandle method but didn't work. i tried also Provider passing context but is always null in this method.

@pragma("vm:entry-point")
  static Future<void> mySilentDataHandle(FcmSilentData silentData) async {

    print("mex: ${silentData.data!["messaggio"]}");
    print("id: ${silentData.data!["idNotifica"]}");

    await AwesomeNotifications().createNotification(
        content: NotificationContent(
            id: int.parse(silentData.data!["idNotifica"]
                .toString()), // -1 is replaced by a random number
            channelKey: 'alerts',
            title: silentData.data!["nome"],
            body: silentData.data!["messaggio"].toString(),
            groupKey: silentData.data!["idNotifica"].toString(),
            largeIcon:
                'https://storage.googleapis.com/cms-storage-bucket/0dbfcc7a59cd1cf16282.png',
            icon: 'resource://drawable/logo',
            notificationLayout: NotificationLayout.Messaging,
            roundedLargeIcon: true,
            summary: ""),
        actionButtons: [
          NotificationActionButton(key: 'REDIRECT', label: 'Redirect'),
          NotificationActionButton(
              key: 'REPLY',
              label: 'Reply Message',
              requireInputText: true,
              actionType: ActionType.SilentBackgroundAction,
              icon:
                  "https://newprofilepic2.photo-cdn.net//assets/images/article/profile.jpg"),
        ]);

    if (silentData.createdLifeCycle != NotificationLifeCycle.Foreground) {
      print("bg");
    } else {
      print("FOREGROUND");
    }

    EventBusSingleton.eventBus.fire(ChatMessageReceivedEvent(silentData.data!));
  }
import 'package:event_bus/event_bus.dart';

class EventBusSingleton {
  static final EventBus _eventBus = EventBus();

  static EventBus get eventBus => _eventBus;
}

this method is copied with small changes from official example in https://pub.dev/packages/awesome_notifications_fcm/example this page (so i created also a singleton class like example page with inside this method).

how can i solve this? thanks!

0 Answers0