'Flutter FirebaseMessaging onBackgroundMessage replace text

I have a Flutter app that able to receive firebase notification when in background state. However I need to replace the text to be show when the background notification receive.

I not able to replace any text and not sure what is the correct way to do it.

// setup the background incoming message
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);

Future firebaseMessagingBackgroundHandler(RemoteMessage message) async {
return message.notification?.title?.replaceAll('key_word', 'KEYWORD');
}


Solution 1:[1]

For FCM : if that notification contains notification object along with data object and when app is in killed state that time that notification handles by system and it wil display that notification direct to the notification tray.

in this case your backgroundlistener for notification will not be fired. if you want that to be fired then send only data messages in notifications.

Please refer this doc : https://firebase.google.com/docs/cloud-messaging/concept-options

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hardik Mehta