на домашней странице вы можете обрабатывать уведомления FCM.
Кроме того, проверьте документацию firebase .
сначала вам нужно отформатировать JSON. Это то, что я следую.
{
"notification": {
"title": "Some title",
"body": "Some text",
},
"data": {
"title": "Some title",
"body": "Some text",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"sound": "default",
"status": "done",
"screen": "OPEN_PAGE1",
"extradata": "",
}
}
firebaseMessaging.configure(
onLaunch: (Map<String, dynamic> msg) {
print("Called onLaunch");
print(msg);
},
onResume: (Map<String, dynamic> msg) {
//(App in background)
// From Notification bar when user click notification we get this event.
// on this event navigate to a particular page.
print(msg);
// Assuming you will create classes to handle JSON data. :)
Notification ns =
Notification(title: msg['title'], body: msg['body']);
Data data = Data(
clickAction: msg['click_action'],
sound: msg['sound'],
status: msg['status'],
screen: msg['screen'],
extradata: msg['extradata'],
);
switch (data.screen) {
case "OPEN_PAGE1":
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Page1()
),
);
break;
default:
break;
},
onMessage: (Map<String, dynamic> msg) {
// (App in foreground)
// on this event add new message in notification collection and hightlight the count on bell icon.
// Add notificaion add in local storage and show in a list.
updataNotification(msg);
},
);