【问题标题】:In firebase_messaging dev14 How to open a screen when user clicks on the notification (background)在 firebase_messaging dev14 用户点击通知时如何打开屏幕(背景)
【发布时间】:2021-04-25 21:07:42
【问题描述】:

我想知道点击通知时如何打开新屏幕。就我而言,如果我点击它,它什么也不做......我希望它(取决于通知)打开应用程序并打开一个新的给定屏幕

这是我现在发送的 json:

'{"notification": {"body": "${body}", "title": "${title}", "click_action": "FLUTTER_NOTIFICATION_CLICK"}, "priority": "high", "to": "MYTOPIC"}';

【问题讨论】:

    标签: firebase flutter dart firebase-cloud-messaging


    【解决方案1】:

    您可以使用此library 生成命名路由,然后在单击通知时执行 onLaunch() 方法,您可以从深层链接中提取路径并将其传递给导航器。

    现在假设您有 2 个屏幕用户屏幕和用户配置文件屏幕。您将在路由器类中定义两条路由。

    MaterialRoute(page: UsersScreen, path : '/users'),
    MaterialRoute(page: UserProfileScreen, path : '/users/:userId?'),
    

    在通知数据负载中,您可以将数据链接作为 /users 或 /users/:userId 传递? ,提取从终止状态触发的 onLaunch 数据并将其传递给您的导航器。您可以查看他们的示例以更好地理解命名路由。

    【讨论】:

    • 但我使用的是 dev-14 版本... onLaunch 已被弃用,onMessageOpenedApp 永远不会被调用
    • 您遇到的这个问题是在 iOS 还是 android 上?
    • Android,我没有在ios中测试过
    • 我正在使用这个版本以外的每个版本似乎对我都有问题,试试这个版本 firebase_messaging: 6.0.9
    • 谢谢您,如果您觉得这个问题有用,请点赞
    猜你喜欢
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多