From 0af9986262e53b232731408ad38e9fda3da2cfa2 Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Wed, 01 Apr 2026 18:02:59 +0200
Subject: [PATCH] feat: smart badge counting, persisted unreads, flutter_app_badger, race condition fixes

---
 lib/services/push_service.dart |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/services/push_service.dart b/lib/services/push_service.dart
index 6f9b306..b246a6b 100644
--- a/lib/services/push_service.dart
+++ b/lib/services/push_service.dart
@@ -1,5 +1,5 @@
 import 'package:flutter/foundation.dart';
-import 'package:flutter/services.dart';
+import 'package:flutter_app_badger/flutter_app_badger.dart';
 import 'package:push/push.dart';
 
 import 'mqtt_service.dart';
@@ -95,14 +95,16 @@
 
   /// Clear the app icon badge number.
   static void clearBadge() {
-    try {
-      // Use UIApplication.shared.applicationIconBadgeNumber = 0 via platform channel
-      const platform = MethodChannel('com.tekmidian.pailot/badge');
-      platform.invokeMethod('clearBadge').catchError((_) {
-        // Fallback: UNUserNotificationCenter approach
-        debugPrint('[Push] clearBadge via platform channel failed, using Push API');
-      });
-    } catch (_) {}
+    FlutterAppBadger.removeBadge();
+  }
+
+  /// Set the app icon badge to a specific count.
+  static void setBadge(int count) {
+    if (count <= 0) {
+      FlutterAppBadger.removeBadge();
+    } else {
+      FlutterAppBadger.updateBadgeCount(count);
+    }
   }
 
   /// Publish the device token to the daemon via MQTT.

--
Gitblit v1.3.1