Please tell me what I'm doing wrong. I send a Cloud Message to my device, and when the application is closed, I want to check how it was launched from Push Notification or not. Also, if the application was opened from Push Notifications, I need to get the data in order to open the corresponding application page.
I found a method that checks whether the application was started by clicking on Push Notification FirebaseMessaging.instance.getInitialMessage()
. But the answer to this call is always null
, I closed the application completely, sent a notification, launched it and always the value = null
. I also use a package to track and display messages: awesome_notification
This is what my code looks like:
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? message) async {
if(message != null){
Get.snackbar('Title', '$message');
auth.testMessage.value = message;
}
});
Request to send a message:
{
"to" : "my_token",
"mutable_content" : true,
"content_available" : true,
"priority" : "high",
"data" : {
"content": {
"id": 100,
"channelKey": "basic_channel",
"title": "Huston!\nThe eagle has landed!",
"body": "A small step for a man, but a giant leap to Flutter's community!",
"notificationLayout": "BigPicture",
"largeIcon": "https://media.fstatic.com/kdNpUx4VBicwDuRBnhBrNmVsaKU=/full-fit-in/290x478/media/artists/avatar/2013/08/neil-i-armstrong_a39978.jpeg",
"bigPicture": "https://www.dw.com/image/49519617_303.jpg",
"showWhen": true,
"autoDismissible": true,
"privacy": "Private"
},
"actionButtons": [
{
"key": "REPLY",
"label": "Reply",
"autoDismissible": true,
"buttonType": "InputField"
},
{
"key": "ARCHIVE",
"label": "Archive",
"autoDismissible": true
}
]
}
}