I am following this answer to handle what happens when a user clicks on a notification: https://stackoverflow.com/a/74288639/4838216
When the user clicks my basic notification, I want it to take them to the notifications page. However, using Navigator.push(...
requires a BuildContext
. I don't think I have one in this case because this is a helper class called FirebaseHelper
. How do I get the context to use here? Or is there another way to do this?
//This method will call when the app is in background state
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage? message) {
if (message != null) {
//Handle push notification redirection here
print('##MyApp## _setUpNotificationListener onMessageOpenedApp.listen');
Navigator.push(context, MaterialPageRoute(builder: (context) => ScreenNotifications()),);
}
});