I use a Navigator in onSelectNotification in Flutter Local Notifications, if the app is already running when I set the notification the Navigator works fine, if the app is closed and opened it via the notification it works fine too because I use didNotificationLaunchApp. However, if the app was closed after setting the notification and was opened again before receiving the notification, the Navigator doesn't work at all. any suggestions?
here is the code
void setNotification(
BuildContext context, int id, int hours, int minutes) async {
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String payload) async {
if (payload != null) {
debugPrint('notification payload: $payload');
}
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PageScreen(
title: payload,
),
),
);
});
await flutterLocalNotificationsPlugin.zonedSchedule(
id,
'Notification Title',
'Notification Body',
_nextInstanceOfTime(hours, minutes),
const NotificationDetails(
android: AndroidNotificationDetails(
'daily notification channel id',
'daily notification channel name',
'daily notification description',
playSound: true,
sound: RawResourceAndroidNotificationSound('pop'),
importance: Importance.max,
priority: Priority.high,
),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
payload: 'Notification Payload',
matchDateTimeComponents: DateTimeComponents.time);
}