简体   繁体   中英

Flutter - How to get current route?

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,
        ...)

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.

You can try this.

ModalRoute.of(context).settings.name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM