diff --git a/lib/core/services/push_notification_service.dart b/lib/core/services/push_notification_service.dart index 3987d3d..ef451bd 100644 --- a/lib/core/services/push_notification_service.dart +++ b/lib/core/services/push_notification_service.dart @@ -164,6 +164,9 @@ class PushNotificationService { } } + /// Callback to refresh notification count when FCM arrives + void Function()? onNotificationReceived; + void _onForegroundMessage(RemoteMessage message) { debugPrint('[FCM] Foreground message: ${message.notification?.title}'); @@ -178,6 +181,9 @@ class PushNotificationService { return; } + // Refresh notification count immediately + onNotificationReceived?.call(); + // Show local notification on Android (iOS handles it natively) if (Platform.isAndroid) { _localNotifications?.show( diff --git a/lib/features/notifications/presentation/providers/notification_provider.dart b/lib/features/notifications/presentation/providers/notification_provider.dart index 9e92d7b..981b3c1 100644 --- a/lib/features/notifications/presentation/providers/notification_provider.dart +++ b/lib/features/notifications/presentation/providers/notification_provider.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:real_estate_mobile/core/services/push_notification_service.dart'; import 'package:real_estate_mobile/core/storage/secure_storage.dart'; import 'package:real_estate_mobile/features/messaging/data/socket_service.dart'; import 'package:real_estate_mobile/features/notifications/data/models/notification_model.dart'; @@ -25,6 +26,8 @@ class UnreadCountNotifier extends StateNotifier { _subs.add(socket.onNewMessage.listen((_) => refresh())); _subs.add(socket.onConnectionRequest.listen((_) => refresh())); _subs.add(socket.onConnectionResponse.listen((_) => refresh())); + // Also refresh when FCM push notification arrives (works even without socket) + PushNotificationService().onNotificationReceived = () => refresh(); } Future refresh() async {