Describe the bug
I am scheduling notifications (using zonedSchedule) in the future but all the notifications are stuck in pending and are never sent.
I can trigger notification immediately using show and it works as expected.
To Reproduce
Future<void> _zonedScheduleNotification() async {
try {
int id = DateTime.now().millisecondsSinceEpoch.remainder(100000);
tz.TZDateTime time = tz.TZDateTime.now(tz.local).add(const Duration(seconds: 10));
await flutterLocalNotificationsPlugin.zonedSchedule(
id,
'scheduled title',
'scheduled body',
time,
const NotificationDetails(
android: AndroidNotificationDetails(
'your channel id', 'your channel name',
importance: Importance.max,
priority: Priority.max,
showWhen: false,
channelDescription: 'your channel description')),
payload: jsonEncode({'id': id, 'time': time.toString()}),
androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
} catch (e) {
print(e);
}
}
I am also logging all pending notifications right after:
Future<void> _checkPendingNotificationRequests() async {
final List<PendingNotificationRequest> pendingNotificationRequests =
await flutterLocalNotificationsPlugin.pendingNotificationRequests();
print('${pendingNotificationRequests.length} pending notification ');
for (PendingNotificationRequest pendingNotificationRequest
in pendingNotificationRequests) {
print(pendingNotificationRequest.id.toString() +
" " +
(pendingNotificationRequest.payload ?? ""));
}
print('NOW ' + tz.TZDateTime.now(tz.local).toString());
}
This is the logs:
I/flutter (18813): 96 {"id":96,"time":"2023-11-01 11:28:25.096493-0700"}
I/flutter (18813): 63018 {"id":63018,"time":"2023-11-01 11:34:28.019017-0700"}
I/flutter (18813): 78087 {"id":78087,"time":"2023-11-01T11:34:43.087746-0700"}
I/flutter (18813): 40156 {"id":40156,"time":"2023-11-01 11:39:10.156216-0700"}
I/flutter (18813): 94279 {"id":94279,"time":"2023-11-01 11:40:04.280062-0700"}
I/flutter (18813): 22924 {"id":22924,"time":"2023-11-01 11:40:32.924866-0700"}
I/flutter (18813): NOW 2023-11-01 11:40:23.148754-0700
I'm also initializing the timezones before running all this.
tz.initializeTimeZones();
final String? timeZoneName = await FlutterTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(timeZoneName!));
I can't figure out what is wrong...
Describe the bug
I am scheduling notifications (using
zonedSchedule) in the future but all the notifications are stuck in pending and are never sent.I can trigger notification immediately using
showand it works as expected.To Reproduce
I am also logging all pending notifications right after:
This is the logs:
I'm also initializing the timezones before running all this.
I can't figure out what is wrong...