Skip to content

How to handle background notifications in flutter web? #10294

Discussion options

You must be logged in to vote

Hi, you can follow these steps

  1. In service worker , post channel messages on receiving fcm
const channel = new BroadcastChannel('sw-messages');

function handleClick(event) {
  console.log("onNotificationClickeventEvent",  event);

  if('FCM_MSG' in event.notification.data)
  {
    console.log("onNotificationClickevent", {'fcm_data': event.notification.data.FCM_MSG, 'clicked' : 'true'});
    channel.postMessage(
      {'fcm_data': event.notification.data.FCM_MSG, 'clicked' : 'true'}
    );
  }
}

 messaging.onBackgroundMessage(function (payload) {

            console.log('Received background message ', payload);
                  
            channel.postMessage(
              payload
 …

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@ChetanKhanna767
Comment options

Answer selected by ChetanKhanna767
@toco1001
Comment options

@i84762
Comment options

@Refaydeen
Comment options

@dsyrstad
Comment options

Comment options

You must be logged in to vote
1 reply
@ChetanKhanna767
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants