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?!