Matthias Nott
2026-04-01 0af9986262e53b232731408ad38e9fda3da2cfa2
lib/services/push_service.dart
....@@ -1,5 +1,5 @@
11 import 'package:flutter/foundation.dart';
2
-import 'package:flutter/services.dart';
2
+import 'package:flutter_app_badger/flutter_app_badger.dart';
33 import 'package:push/push.dart';
44
55 import 'mqtt_service.dart';
....@@ -95,14 +95,16 @@
9595
9696 /// Clear the app icon badge number.
9797 static void clearBadge() {
98
- try {
99
- // Use UIApplication.shared.applicationIconBadgeNumber = 0 via platform channel
100
- const platform = MethodChannel('com.tekmidian.pailot/badge');
101
- platform.invokeMethod('clearBadge').catchError((_) {
102
- // Fallback: UNUserNotificationCenter approach
103
- debugPrint('[Push] clearBadge via platform channel failed, using Push API');
104
- });
105
- } catch (_) {}
98
+ FlutterAppBadger.removeBadge();
99
+ }
100
+
101
+ /// Set the app icon badge to a specific count.
102
+ static void setBadge(int count) {
103
+ if (count <= 0) {
104
+ FlutterAppBadger.removeBadge();
105
+ } else {
106
+ FlutterAppBadger.updateBadgeCount(count);
107
+ }
106108 }
107109
108110 /// Publish the device token to the daemon via MQTT.