Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 单击推送通知时,如何在我的颤振应用程序中打开特定页面_Firebase_Push Notification_Flutter_Firebase Cloud Messaging - Fatal编程技术网

Firebase 单击推送通知时,如何在我的颤振应用程序中打开特定页面

Firebase 单击推送通知时,如何在我的颤振应用程序中打开特定页面,firebase,push-notification,flutter,firebase-cloud-messaging,Firebase,Push Notification,Flutter,Firebase Cloud Messaging,单击推送通知时,如何在我的颤振应用程序中打开特定页面。我已经创建了一个php脚本来推送FCM推送通知,但它刚刚打开应用程序首页。。。。。我希望推送通知包含日期,并在我的应用程序中打开日历页,显示通知的详细信息 在主页中,您可以处理FCM通知 此外,请检查文档 首先,您需要格式化JSON。这就是我所遵循的 { "notification": { "title": "Some title", "body": "Some text",

单击推送通知时,如何在我的颤振应用程序中打开特定页面。我已经创建了一个php脚本来推送FCM推送通知,但它刚刚打开应用程序首页。。。。。我希望推送通知包含日期,并在我的应用程序中打开日历页,显示通知的详细信息


在主页中,您可以处理FCM通知

此外,请检查文档

首先,您需要格式化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);
  },
);
{
“通知”:{
“头衔”:“某个头衔”,
“正文”:“一些文本”,
},
“数据”:{
“头衔”:“某个头衔”,
“正文”:“一些文本”,
“点击动作”:“颤振通知点击”,
“声音”:“默认值”,
“状态”:“完成”,
“屏幕”:“打开页面1”,
“外部数据”:“,
}
}
firebaseMessaging.configure(
onLaunch:(地图消息){
打印(“称为onLaunch”);
印刷品(味精);
},
onResume:(映射消息){
//(后台应用程序)
//当用户单击通知时,我们从通知栏获得此事件。
//在此事件中,导航到特定页面。
印刷品(味精);
//假设您将创建类来处理JSON数据。:)
通知ns=
通知(标题:msg['title',正文:msg['body']);
数据=数据(
clickAction:msg['click_action'],
声音:msg['sound'],
状态:msg['status'],
屏幕:msg['screen'],
extradata:msg['extradata'],
);
开关(数据屏幕){
案例“打开页面1”:
导航器。推(
上下文
材料路线(
生成器:(上下文)=>Page1()
),
);
打破
违约:
打破
},
onMessage:(映射消息){
//(前台应用程序)
//在此事件中,在通知集合中添加新消息,并高亮显示计数钟图标。
//在本地存储中添加通知加载项并显示在列表中。
更新(msg);
},
);

这为我修复了它。在初始化FirebaseApp和FirebaseMessaging之后放置它

var _message = await FirebaseMessaging.instance.getInitialMessage();

if (_message != null) {
  // DO THE ROUTING

}

好的,这很好。我理解的基本上是我们需要在main.dart中添加这些代码,然后我们可以重定向到其他页面。如果我错了,请纠正我。@Rocx您的理解是正确的!!!我仍在努力解决它。:(