onMessageReceivedInTheForeground method

  1. @override
Future<void> onMessageReceivedInTheForeground(
  1. OnMessageReceivedInTheForeground callback
)
override

Registers a listener which calls back the OnMessageReceivedInTheForeground function when the app receives a push notification in the foreground. This is not implemented on web.

Notification is a map containing the following keys:

  • title
  • body
  • data

Example Usage

function someAsyncFunction() async {
  await PusherBeams.instance.onMessageReceivedInTheForeground((notification) => {
    print('Message received in the foreground: $notification')
  });
}

Throws an Exception in case of failure.

Implementation

@override
Future<void> onMessageReceivedInTheForeground(
    OnMessageReceivedInTheForeground callback) async {
  final callbackId = _uuid.v4();

  if (!kIsWeb) {
    _callbacks[callbackId] = callback;
  }

  await _pusherBeamsApi
      .onMessageReceivedInTheForeground(kIsWeb ? callback : callbackId);
}