|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
|
@ -120,8 +121,6 @@ class NotificationsProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Mark all notifications as read
|
|
|
|
|
/// Returns a map with success status and message from API
|
|
|
|
|
Future<Map<String, dynamic>> markAllAsRead({required String userId}) async {
|
|
|
|
|
try {
|
|
|
|
|
final Map<String, dynamic> body = {"userId": userId};
|
|
|
|
|
@ -159,8 +158,6 @@ class NotificationsProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Mark one notification as read
|
|
|
|
|
/// Returns true if successful, false otherwise
|
|
|
|
|
Future<bool> markOneAsRead({required String notificationId}) async {
|
|
|
|
|
try {
|
|
|
|
|
final response = await ApiManager.instance.get("${URLs.markOneNotificationAsRead}?NotificationId=$notificationId", enableToastMessage: false);
|
|
|
|
|
@ -188,11 +185,53 @@ class NotificationsProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// return -2 if request in progress
|
|
|
|
|
/// return -1 if error happen when sending request
|
|
|
|
|
/// return state code if request complete may be 200, 404 or 403
|
|
|
|
|
/// for more details check http state manager
|
|
|
|
|
/// lib\controllers\http_status_manger\http_status_manger.dart
|
|
|
|
|
Future<int?> getUnreadCount() async {
|
|
|
|
|
int? count;
|
|
|
|
|
try {
|
|
|
|
|
final response = await ApiManager.instance.get(URLs.getUnreadNotificationCount, enableToastMessage: false);
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
final responseData = json.decode(response.body);
|
|
|
|
|
log('count response :: $responseData');
|
|
|
|
|
count = responseData['data'];
|
|
|
|
|
// Update the totalNotificationUnread property
|
|
|
|
|
totalNotificationUnread = count ?? 0;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
print('Error getting unread notification count: $error');
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Manually reset the unread count to zero
|
|
|
|
|
/// Useful when you want to clear the badge without making an API call
|
|
|
|
|
void resetUnreadCount() {
|
|
|
|
|
totalNotificationUnread = 0;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Update unread count manually (e.g., from push notification)
|
|
|
|
|
/// Useful when you receive a notification and want to increment the badge
|
|
|
|
|
void updateUnreadCount(int newCount) {
|
|
|
|
|
totalNotificationUnread = newCount;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Increment unread count by 1 (e.g., when receiving a new push notification)
|
|
|
|
|
void incrementUnreadCount() {
|
|
|
|
|
totalNotificationUnread++;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Decrement unread count by 1 (e.g., when marking one as read locally)
|
|
|
|
|
void decrementUnreadCount() {
|
|
|
|
|
if (totalNotificationUnread > 0) {
|
|
|
|
|
totalNotificationUnread--;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<List<SystemNotificationModel>?> getRecentNotifications({
|
|
|
|
|
required String host,
|
|
|
|
|
required User user,
|
|
|
|
|
|