updateBadgeCount method
Updates the app icon badge count.
On iOS and Android, this updates the badge number shown on the app icon. On web, badge support varies by browser.
Set count to 0 to clear the badge.
Emits the new count to badgeCountStream for reactive UI updates.
Implementation
Future<void> updateBadgeCount(int count) async {
try {
// Update internal state
_currentBadgeCount = count;
// Emit to stream for reactive UI updates
if (!_badgeCountController.isClosed) {
_badgeCountController.add(count);
}
// Update platform badge via app_badge_plus
// Note: Requires platform permissions (see NOTIFICATION_GUIDE.md)
try {
await AppBadgePlus.updateBadge(count);
} catch (e) {
// Badge update failed - this is non-critical
logi('Badge update failed (platform may not support badges): $e');
}
logi('Badge count updated to: $count');
} catch (e, stackTrace) {
loge(e, 'Failed to update badge count', stackTrace);
_onError?.call('Failed to update badge count: $e', stackTrace);
}
}