Home > Software engineering >  Flutter how to open page from push notification, context issue
Flutter how to open page from push notification, context issue

Time:09-10

void selectNotification(String? payload) async {
    print('Selected notification');
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => SearchScreen(),
      ),
    );
  }

I am using this method to open a screen when the notification is tapped, I get the print message fine but then the Navigator message shows:

The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.

Im just trying to have it so if the notificaiton is tapped from foreground, background where ever the app then just pops open that screen but I cant get it to work

CodePudding user response:

void selectNotification(String? payload, BuildContext context) async {
    print('Selected notification');
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => SearchScreen(),
      ),
    );
  }

CodePudding user response:

Use getX package and use navigation routing: something like this: Get.put(()=> **your page**

getX package

  • Related