0

I need help with notifications in flutter. I have configured firebase_messaging in my flutter app. When i send test notifications from the firebase console they work in both foreground and background. When i send the notifications from a backend rest api service, they only work in the foreground.I.e only onMessage is triggered in this case.

sample notification body from REST API:

{notification: {title: null, body: null}, data: {intent: payment, body: 2500 shillings payment made, title: You have paid, click_action: FLUTTER_NOTIFICATION_CLICK}}
RaSha
  • 1,356
  • 1
  • 16
  • 30
pyamo
  • 1
  • 1

1 Answers1

0

 you should add "content_available": true on your notification payload. Try this payload to send notification.

{ 
"to": "your title name", 
"content_available": true,
 "notification": {
 "title": "TITLE TEXT", 
"body": "BODY TEXT",
 "content_available": true
 },
 "data": { 
"body": "BODY TEXT",
 "title": "TITLE TEXT", 
"click_action": "FLUTTER_NOTIFICATION_CLICK"
 }
 }
Shirsh Shukla
  • 5,491
  • 3
  • 31
  • 44
  • Thanks shirsh. My problem was providing null values to title and body in the notification. { notification: { title: null, body: null, }, data: { intent: payment, body: "BODY TEXT", title: "TITLE TEXT", click_action: FLUTTER_NOTIFICATION_CLICK } } – pyamo Nov 18 '20 at 11:31
  • if is is helpful then set this as accept answer(blue tick)this. – Shirsh Shukla Nov 18 '20 at 12:51