From dd2d51e1ce358f71bd2de766e113e7ef74be3a7e Mon Sep 17 00:00:00 2001 From: ssbg04 Date: Tue, 18 Aug 2026 16:50:17 +0800 Subject: [PATCH] fix(notifications): prevent duplicate pop-up banner when launching app from background notification --- .../ui/providers/notification_provider.dart | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/frontend/lib/ui/providers/notification_provider.dart b/frontend/lib/ui/providers/notification_provider.dart index 68ef3cb..c23f154 100644 --- a/frontend/lib/ui/providers/notification_provider.dart +++ b/frontend/lib/ui/providers/notification_provider.dart @@ -34,29 +34,10 @@ class NotificationNotifier extends AsyncNotifier> { final repo = ref.read(notificationRepositoryProvider); final list = await repo.getNotifications(); - // Check if there are any unread notifications on initial load + // On initial app load, sync last_seen_notification_id to latest without re-popping banners for past items if (list.isNotEmpty) { final prefs = await SharedPreferences.getInstance(); final highestOldId = prefs.getInt('last_seen_notification_id') ?? 0; - - final newNotes = list.where((e) { - if (!e.isRead) { - if (highestOldId == 0) return true; - return e.id > highestOldId; - } - return false; - }).toList(); - - if (newNotes.isNotEmpty) { - for (var note in newNotes) { - await NotificationService().showNotification( - id: note.id, - title: note.title, - body: note.message, - ); - } - } - final highestId = list.map((e) => e.id).reduce(math.max); await prefs.setInt('last_seen_notification_id', math.max(highestOldId, highestId)); } @@ -74,8 +55,7 @@ class NotificationNotifier extends AsyncNotifier> { if (list.isNotEmpty) { final newNotes = list.where((e) { - if (!e.isRead) { - if (highestOldId == 0) return true; + if (!e.isRead && highestOldId > 0) { return e.id > highestOldId; } return false;