I am using flutter and for local notification awesome-notification package. I create a notification and send it to the user. When the user clicks on the notification, I will redirect to another page. When the notification that comes on every page of the application is clicked, I will direct you to the page. but this code only listens on the page I put. Where should I put it to listen on each page?
AwesomeNotifications()
.actionStream
.listen((ReceivedNotification receivedNotification) async {
if (channels.contains(receivedNotification.channelKey)) {
print('event received!');
print(receivedNotification.toMap().toString());
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrganizerNotificationScreen(
taskId: receivedNotification.id.toString(),
taskBody: receivedNotification.body,
taskChannel: receivedNotification.channelKey,
),
));
}
});
To listen on all pages of your application, run this code in the
initState
of the first page. and usestatic
andasync
await