Matthias Nott
2026-04-01 e7c5b5de5160f3d82fc9c36bc5185b5c6e091e9e
lib/services/push_service.dart
....@@ -1,4 +1,5 @@
11 import 'package:flutter/foundation.dart';
2
+import 'package:flutter/services.dart';
23 import 'package:push/push.dart';
34
45 import 'mqtt_service.dart';
....@@ -82,13 +83,26 @@
8283 };
8384 }
8485
85
- /// Re-send the last known token when MQTT reconnects.
86
+ /// Re-send the last known token when MQTT reconnects, and clear badge.
8687 void onMqttConnected() {
8788 final token = _lastToken;
8889 if (token != null) {
8990 debugPrint('[Push] re-registering token after MQTT reconnect');
9091 _sendTokenToDaemon(token);
9192 }
93
+ clearBadge();
94
+ }
95
+
96
+ /// Clear the app icon badge number.
97
+ 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 (_) {}
92106 }
93107
94108 /// Publish the device token to the daemon via MQTT.