0

I want to navigate to a screen on notification tap, but I can't context in OneSignal.shared.setNotificationOpenedHandler, I tried using global navigator key as below.

OneSignal.shared.setNotificationOpenedHandler(
        (final OSNotificationOpenedResult result) {
      const String s1 = 'Your account has been credited with';
      const String s2 = 'New gift product has been added to your account';
      final String? body = result.notification.body;

      final int productId = result.notification.additionalData!['product_id'];

// tried it without the delay 
// tried it with addPostFramecallback
// all don't work
      Future.delayed(Duration(milliseconds: 100), () {
        navigatorKey.currentState!.pushReplacement(
          MaterialPageRoute(builder: (_) => SomePage()),
        );

        print('After the frame has been painted');
      });
    });

My navigator is set up like this

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
  return GetMaterialApp(
                title: 'Crown Store',
                theme: theme,
                navigatorKey: navigatorKey,
                debugShowCheckedModeBanner: false,
                home: const SplashScreen(),
              );
            }),

Now when I click on the notification, it just opens the app and nothing else?!

Mary
  • 205
  • 1
  • 2
  • 6

1 Answers1

0

my code was stopping execution at final int productId = result.notification.additionalData!['product_id']; because of wrong data type now everything works

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 05 '23 at 21:45