Flutter - How to format title and body of notification in background?

百般思念 提交于 2021-02-11 15:01:42

问题


I am trying to display localized notification in flutter using firebase_messaging, I am getting a json with 3 language strings in body of a notification like so:

{"it": "italian text", "de": "german text", "en": "english text"}

As of now, it is showing the whole json string in the notification tray. How can I select the appropriate language text from the json and show in notification when app is in background? myBackgroundMessageHandler this function is never called. Thanks.


回答1:


I could not get myBackgroundMessageHandler function to call when in background. I did find a couple of ways to localize notifications using loc_key like tags in iOS like this and in android like this.

However, this method was not suitable for my case because I had to send a bulk text (for example for sending promotions) in the notification. So I ended up saving the device's language in the backend when user subscribes something. That way backend can send the notification only in that language to that device.



来源:https://stackoverflow.com/questions/64804684/flutter-how-to-format-title-and-body-of-notification-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!