feat: trigger notification provider refresh upon receiving FCM push notifications
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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<int> {
|
||||
_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<void> refresh() async {
|
||||
|
||||
Reference in New Issue
Block a user