我在 Flutter Local Notifications 的 onSelectNotification 中使用 Navigator,如果在我设置通知时应用程序已经在运行,Navigator 工作正常,如果应用程序关闭并通过通知打开它也工作正常,因为我使用了 didNotificationLaunchApp。 但是,如果应用程序在设置通知后关闭,并在收到通知之前再次打开,则导航器根本不起作用。有什么建议么?
这是代码
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);
}