Function 如何在通知单击时将用户重定向到页面

Function 如何在通知单击时将用户重定向到页面,function,flutter,cloud,Function,Flutter,Cloud,我正在使用firebase服务器开发Flitter应用程序和web。我使用云函数发送通知。当用户收到通知并单击时,我想将其重定向到特定页面。现在,当我收到通知并点击时,我的应用程序会显示“主页”。当用户收到通知并单击它时,我如何重定向到“请求详细信息页面”而不是“主页”?将此添加到AndroidManifest文件中 <intent-filter> <action android:name="FLUTTER_NOTIFICATION_CLICK" /&g

我正在使用firebase服务器开发Flitter应用程序和web。我使用云函数发送通知。当用户收到通知并单击时,我想将其重定向到特定页面。现在,当我收到通知并点击时,我的应用程序会显示“主页”。当用户收到通知并单击它时,我如何重定向到“请求详细信息页面”而不是“主页”?

将此添加到AndroidManifest文件中

<intent-filter>
  <action android:name="FLUTTER_NOTIFICATION_CLICK" />
  <category android:name="android.intent.category.DEFAULT" />
当用户单击通知时,这三个事件中的一个将根据您的应用程序状态触发

_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    print("onMessage: $message");
    _showItemDialog(message);
  },
  onBackgroundMessage: myBackgroundMessageHandler,
  onLaunch: (Map<String, dynamic> message) async {
    print("onLaunch: $message");
    _navigateToItemDetail(message);
  },
  onResume: (Map<String, dynamic> message) async {
    print("onResume: $message");
    _navigateToItemDetail(message);
  },
);
\u firebaseMessaging.configure(
onMessage:(映射消息)异步{
打印(“onMessage:$message”);
_showItemDialog(消息);
},
onBackgroundMessage:myBackgroundMessageHandler,
onLaunch:(映射消息)异步{
打印(“onLaunch:$message”);
_导航项目详细信息(消息);
},
onResume:(映射消息)异步{
打印(“onResume:$message”);
_导航项目详细信息(消息);
},
);

从消息中检索通知数据并导航到所需页面。

将此添加到AndroidManifest文件中

<intent-filter>
  <action android:name="FLUTTER_NOTIFICATION_CLICK" />
  <category android:name="android.intent.category.DEFAULT" />
当用户单击通知时,这三个事件中的一个将根据您的应用程序状态触发

_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    print("onMessage: $message");
    _showItemDialog(message);
  },
  onBackgroundMessage: myBackgroundMessageHandler,
  onLaunch: (Map<String, dynamic> message) async {
    print("onLaunch: $message");
    _navigateToItemDetail(message);
  },
  onResume: (Map<String, dynamic> message) async {
    print("onResume: $message");
    _navigateToItemDetail(message);
  },
);
\u firebaseMessaging.configure(
onMessage:(映射消息)异步{
打印(“onMessage:$message”);
_showItemDialog(消息);
},
onBackgroundMessage:myBackgroundMessageHandler,
onLaunch:(映射消息)异步{
打印(“onLaunch:$message”);
_导航项目详细信息(消息);
},
onResume:(映射消息)异步{
打印(“onResume:$message”);
_导航项目详细信息(消息);
},
);

从消息中检索通知数据并导航到所需页面。

SecondScreen是其他屏幕的类名

_firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {

         Navigator.push(context,
                MaterialPageRoute(builder: (BuildContext context) {
              return SecondScreen(
                message,
              );
            }));

        print("onMessage: $message");
        _showItemDialog(message);
      },
     
    );
\u firebaseMessaging.configure(
onMessage:(映射消息)异步{
Navigator.push(上下文,
MaterialPage路由(生成器:(构建上下文){
返回第二屏幕(
消息
);
}));
打印(“onMessage:$message”);
_showItemDialog(消息);
},
);

SecondScreen是其他屏幕的类名

_firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {

         Navigator.push(context,
                MaterialPageRoute(builder: (BuildContext context) {
              return SecondScreen(
                message,
              );
            }));

        print("onMessage: $message");
        _showItemDialog(message);
      },
     
    );
\u firebaseMessaging.configure(
onMessage:(映射消息)异步{
Navigator.push(上下文,
MaterialPage路由(生成器:(构建上下文){
返回第二屏幕(
消息
);
}));
打印(“onMessage:$message”);
_showItemDialog(消息);
},
);

感谢您的回复Shanto,什么是产品id:1?这只是一个例子,还是我需要像你那样做?这只是一个例子。你能给我看一些_navigateToItemDetail(message)函数的例子吗?谢谢你的回复Shanto,什么是产品_id:1?这只是一个例子,还是我需要像你那样做?这只是一个例子。你能给我看一些_navigateToItemDetail(message)函数的例子吗?谢谢你的回复穆罕默德,onResume和onLaunch呢?我是否也需要为它们编写相同的导航器函数?是的,您需要编写相同的导航器函数。我尝试了此操作,但应用程序仍然没有显示“请求详细信息页面”。它只显示“主页”是的,您必须浏览每种类型的消息,如onMessage、onBackgroundMessage、onResume。如果没有发生这种情况,则打印这些消息中的某些内容,这些功能可能在您单击通知时未被调用。就像下面的代码onMessage:(映射消息)async{print(“onMessage:$message”);},谢谢你的回复,穆罕默德,onResume和onLaunch呢?我是否也需要为它们编写相同的导航器函数?是的,您需要编写相同的导航器函数。我尝试了此操作,但应用程序仍然没有显示“请求详细信息页面”。它只显示“主页”是的,您必须浏览每种类型的消息,如onMessage、onBackgroundMessage、onResume。如果没有发生这种情况,则打印这些消息中的某些内容,这些功能可能在您单击通知时未被调用。像下面的代码onMessage:(映射消息)async{print(“onMessage:$message”);},