我正在与firebase服务器的颤动应用程序和网络工作。我使用云函数发送通知。我希望当用户收到通知并单击该页面时,将其重定向到特定页面。目前,当我收到通知并点击它时,我的应用程序会显示“主页”。当用户收到通知并点击时,我如何重定向到“请求详细信息页面”而不是“主页”?
发布于 2021-01-06 22:19:42
在AndroidManifest文件中添加此文件
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />在通知数据中,添加click_action和导航到特定页面所需的参数
'data': {
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'product_id': 1,
...
},当用户点击通知时,这三个事件中的一个将根据您的应用程序状态触发。
_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);
},
);从消息中检索通知数据并导航到所需的页面。
发布于 2021-01-06 23:53:59
SecondScreen是其他屏幕的类名。
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
Navigator.push(context,
MaterialPageRoute(builder: (BuildContext context) {
return SecondScreen(
message,
);
}));
print("onMessage: $message");
_showItemDialog(message);
},
);https://stackoverflow.com/questions/65597291
复制相似问题