如何在单击推送通知时打开特定屏幕以进行颤动

新手上路,请多包涵

我试图在单击推送通知时实现打开特定屏幕,我的有效负载如下所示:

  var payload = {
        notification: {
            title: notificationTitle,
            body: notificationMessage,
            click_action:"/screena",sound:"default",
        }
    };

我收到通知,但我无法捕捉通知点击事件,如何捕捉它。我正在使用颤振消息传递

https://github.com/flutter/plugins/tree/master/packages/firebase_messaging

我的firebase推送消息服务代码看起来像这样

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

  print("I am here in on message");
  print(message);
},
onLaunch: (Map<String, dynamic> message) {
  print("I am here onLaunch");
  print(message);
},
onResume: (Map<String, dynamic> message) {
  print("I am hereonResume");
  print(message);
},
);
  messagingreference.requestNotificationPermissions(
  const IosNotificationSettings(sound: true, badge: true, alert: true));
 messagingreference.onIosSettingsRegistered
  .listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
 });
 messagingreference.getToken().then((String token) async {

print(token);
 });
 }

在这里,当我的应用程序在前台时,我可以收到消息,正如@xqwzts 在消息中所说,但我的问题是如何从系统托盘中提出的推送通知中捕获点击事件并导航到所需的屏幕。

原文由 siva kumar 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 388
1 个回答
 FirebaseMessaging.instance.getInitialMessage().then((message) {
  RemoteNotification notification = message.notification;
  AndroidNotification android = message.notification?.android;
  if (notification != null && android != null) {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => NotificationScreen(
          name: message.data['name'],
          place: message.data['place'],
          address: message.data['address'],
        ),
      ),
    );
  }
});// handles notification clicks while the app is in the terminated state

原文由 Unais IB 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题