From e7c5b5de5160f3d82fc9c36bc5185b5c6e091e9e Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Wed, 01 Apr 2026 13:06:18 +0200
Subject: [PATCH] fix: clear badge on app open, add clearBadge method
---
lib/services/push_service.dart | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/lib/services/push_service.dart b/lib/services/push_service.dart
index e9e09b6..6f9b306 100644
--- a/lib/services/push_service.dart
+++ b/lib/services/push_service.dart
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
import 'package:push/push.dart';
import 'mqtt_service.dart';
@@ -82,13 +83,26 @@
};
}
- /// Re-send the last known token when MQTT reconnects.
+ /// Re-send the last known token when MQTT reconnects, and clear badge.
void onMqttConnected() {
final token = _lastToken;
if (token != null) {
debugPrint('[Push] re-registering token after MQTT reconnect');
_sendTokenToDaemon(token);
}
+ clearBadge();
+ }
+
+ /// 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 (_) {}
}
/// Publish the device token to the daemon via MQTT.
--
Gitblit v1.3.1