MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.47k stars 1.4k forks source link

getActiveNotifications function does not work for notifications that are created later with the ongoing property set to true. #2426

Closed muhammetikbalkeklik closed 3 weeks ago

muhammetikbalkeklik commented 1 month ago

Handling Multiple Active Zoned Notifications

Description: We are using the flutter_local_notifications package to schedule multiple notifications. Among these, some notifications are scheduled as zonedNotification with the ongoing property set to true. However, there is an unexpected behavior occurring: when the time for the notifications arrives, sometimes two notifications remain active simultaneously. This is not the desired outcome.

Ideally, when the user interacts with (taps on) one of these notifications, the issue should resolve itself by closing other active notifications. However, the following problem occurs:

The function:

var activeNotificationList = await flutterLocalNotificationsPlugin.getActiveNotifications(); does not correctly detect a zonedScheduleNotification that becomes active after it is triggered. In fact, it sometimes returns 0, indicating no active notifications even when there are ongoing notifications. This means that the newly active notifications are not properly identified and managed, leading to multiple ongoing notifications being displayed at the same time.

my example code :

var aktifNotificationList = await flutterLocalNotificationsPlugin.getActiveNotifications(); if (aktifNotificationList.length !=1) { for (var notification in aktifNotificationList) { if (notification.id! >= 15000) { await flutterLocalNotificationsPlugin.cancel(notification.id!); } } }

muhammetikbalkeklik commented 3 weeks ago

When I corrected my own codes the problem was solved.