Flutter - How to get current route?

Viewed 568

I recevice a remote notification, and it will call the method below. In this method, I will judge which current route it is, And excute diffrent method.

   jPush.addEventHandler(
        onReceiveNotification: (Map<String, dynamic> message) async {

      // How to get current display route here?
   });

How to get current display route here? There is no context here. In main.dart, I define a navigatorKey.

MaterialApp(
        title: '',
        navigatorKey: MyRouters.navigatoeKey,
        ...)
1 Answers

As far as I know you can not get the current route without the app context. I can suggest a workaround here, save the current route in state management. When notification arrives, just check the state value to get the current route.

Related