Flutter 如何从通知栏导航到页面

问题描述 投票:0回答:1

我通过 Firebase 消息发送用户通知以检查他们的日历。当用户单击通知消息时,我希望应用程序导航到日历页面。

问题是,如果他们点击消息,那么他们必须先登录。

一旦他们登录,它就会进入主页,而不是我想要的页面。

该页面如何保持登录状态,以便它进入我的应用程序中的日历屏幕。

这是 Firebase Messaging 的入口点所在的位置。这是在我的 Main.Dart 中

Future<void> setupInteractedMessage() async {
    // Get any messages which caused the application to open from
    // a terminated state.
    RemoteMessage? initialMessage =
        await FirebaseMessaging.instance.getInitialMessage();

    // If the message also contains a data property with a "type" of "chat",
    // navigate to a chat screen
    if (initialMessage != null) {
      _handleMessage(initialMessage);
    }

    // Also handle any interaction when the app is in the background via a
    // Stream listener
    FirebaseMessaging.onMessageOpenedApp.listen(_handleMessage);
  }

  void _handleMessage(RemoteMessage message) {
    if (message.data['type'] == 'calendar') {
      Logger().w('Calendar is selected. Need to Navigate here');
      
    }
  }
flutter firebase-cloud-messaging
1个回答
0
投票

希望可以帮到你!

您可以使用

NavigatorKey
来推送您想要的页面。

在消息数据中,您应该输入所需页面的路由器名称(Compose notification firebase 中的示例): enter image description here

并将代码添加到handlemessage函数中:

final route = message.data["route"];
navigatorKey.currentState?.pushNamed(
    route,
    arguments: message
);
© www.soinside.com 2019 - 2024. All rights reserved.