Closed giacomomasseron closed 5 years ago
@GiacomoK Are you getting an error message...? Can you use a print statement to see if the NotificationOpenedHandler
is actually being called?
There could be so many possible problems here, it's hard to help you without more details. I would test with the NotificationReceivedHandler
first, it's easier to debug, so that you can make sure your UI logic actually works...
@Nightsd01 I tried with this code:
OneSignal.shared.setNotificationReceivedHandler((OSNotification notification) {
print("setNotificationReceivedHandler");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AnotherScreen(),
),
);
});
OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
print("setNotificationOpenedHandler");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AnotherScreen(),
),
);
});
And when I receive the notification I see "setNotificationReceivedHandler" on the log, but nothing else happens, the app (if its in foreground) remains on the same screen.
If I tap on the notification, I see "setNotificationOpenedHandler" on the log, but nothing else happens.
@GiacomoK that would mean this is an issue with how you are using Navigator.push(...
. I would suggest debugging your UI code.
Since the opened handler is being called, this would not be a problem with our SDK.
When I have some time this weekend I will test your code but in the mean time if you figure out a solution please post it here as I’m sure other users will have a similar question
@Nightsd01 I use the same Navigator code in other part of the application and it works :(
I will try other things and let you know.
@GiacomoK Closing due to inactivity. Feel free to reply if you are still seeing this issue.
Any update, facing same issue.
@flakerimi This issue may be fixed in the latest 2.0.1 release. Can you follow the 2.0.0 migration guide and give it a try? https://github.com/OneSignal/OneSignal-Flutter-SDK/releases
still facing same issue unable to navigate when click on notification, any solution
Navigator.push not work . Any update, facing same issue.
You need to call .push() on the same Navigator object you istance in your MaterialApp.
this worked fine for me.
You need to call .push() on the same Navigator object you istance in your MaterialApp.
this worked fine for me.
Thanks it is work
How to pass argument with route name?
{ "app_id": "YOUR_APP_ID", "included_segments": ["All"], "data": { "target": "specific_page", "page_id": "page_identifier" }, "contents": { "en": "Notification message" } }
OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) { log("--------NotificationOpenedHandler---------"); var data = result.notification.additionalData; print(data); try { if (data != null) { // navigatorKey.currentState!.push(MaterialPageRoute( // builder: (context) => TestAds(postId: data["post_id"].toString()), // )); navigatorKey.currentState!.pushReplacement(MaterialPageRoute( builder: (context) => TestAds(postId: data["post_id"].toString()), )); } else { // navigate to another screen } } catch (e) { log(e.toString()); } });
After struggling with the latest versions and trying all the suggested solutions, here's what worked for me:
Step 1: Define the Global Navigator Key
final GlobalKey
Step 2: Configure MaterialApp.router
MaterialApp.router( debugShowCheckedModeBanner: false, title: 'News Television', theme: darkTheme, darkTheme: darkTheme, routerConfig: router, );
Step 3: Navigate to the Desired Screen
navigatorKey.currentState?.push( MaterialPageRoute( builder: (context) => NewsReadScreen( id: data['post_id'].toString(), title: data['Title'], content: data['Content'] ?? '', date: data['Date'], pagePath: data['post_link'], image: data['post_image'], ), ), );
These setups resolved my issues with navigation in the latest versions.
This is what worked for me
CODE :
class MyApp extends StatelessWidget { const MyApp({super.key});
static final navigatorKey = GlobalKey
@override Widget build(BuildContext context) { int? lead_id; OneSignal.Notifications.addClickListener((event) { final data = event.notification.additionalData; lead_id = data?['lead_id']; if (lead_id != null) { navigatorKey.currentState?.push( MaterialPageRoute( builder: (context) => LeadDetailScreen( leadId: lead_id, ), ), ); } log(" DATA =====> $lead_id"); }); return MaterialApp( navigatorKey: navigatorKey, theme: ThemeData(appBarTheme: const AppBarTheme(color: Colors.white)), debugShowCheckedModeBanner: false, home: const LoginScreen(), ); } }
POST : https://api.onesignal.com/notifications
{ "app_id": "APP ID", "contents": { "en": "New Lead Alert" }, "data":{ "lead_id": 18294 }, "target_channel": "push", "include_subscription_ids": [ "SUBSCRIPTION ID" ] }
Description:
I need to navigate to a screen when the notification is opened, but I can't get it.
The app just is opened in main screen.
Environment onesignal: ^1.0.0
Steps to Reproduce Issue:
This is the code of my main.dart:
Anything else:
(crash stacktraces, as well as any other information here)