| .. | .. |
|---|
| 1 | 1 | import 'package:flutter/foundation.dart'; |
|---|
| 2 | | -import 'package:flutter/services.dart'; |
|---|
| 2 | +import 'package:flutter_app_badger/flutter_app_badger.dart'; |
|---|
| 3 | 3 | import 'package:push/push.dart'; |
|---|
| 4 | 4 | |
|---|
| 5 | 5 | import 'mqtt_service.dart'; |
|---|
| .. | .. |
|---|
| 95 | 95 | |
|---|
| 96 | 96 | /// Clear the app icon badge number. |
|---|
| 97 | 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 (_) {} |
|---|
| 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 | + } |
|---|
| 106 | 108 | } |
|---|
| 107 | 109 | |
|---|
| 108 | 110 | /// Publish the device token to the daemon via MQTT. |
|---|