Added unread list api in notification

This commit is contained in:
llsajjad
2025-09-23 15:49:30 +03:30
parent 70066c26e8
commit 1f60954c53
5 changed files with 86 additions and 22 deletions
+35 -1
View File
@@ -11,6 +11,7 @@ class NotificationViewModel with ChangeNotifier {
: _repository = repositoryViewModel {
WidgetsBinding.instance.addPostFrameCallback((_) {
getNotifications();
getUnreadNotifications();
});
}
@@ -30,6 +31,13 @@ class NotificationViewModel with ChangeNotifier {
bool get hasMoreData => _hasMoreData;
int get totalPages => _totalPages;
NotificationResponseModel? _unreadNotificationResponse;
bool _isUnreadLoading = false;
NotificationResponseModel? get unreadNotificationResponse =>
_unreadNotificationResponse;
bool get isUnreadLoading => _isUnreadLoading;
/// Fetch notifications
Future<void> getNotifications({int page = 1, bool isMobile = false}) async {
_isLoading = true;
@@ -110,7 +118,9 @@ class NotificationViewModel with ChangeNotifier {
);
}
await getNotifications(page: 1);
await getNotifications(page: currentPage, );
await getUnreadNotifications();
// toast success
AppToast.success(context, 'All notifications marked as read.');
@@ -147,4 +157,28 @@ class NotificationViewModel with ChangeNotifier {
return '${difference.inDays} days ago';
}
}
Future<void> getUnreadNotifications({int page = 1}) async {
_isUnreadLoading = true;
notifyListeners();
final int offset = _pageSize * page;
final result = await _repository.getUnreadNotifications(
limit: _pageSize,
offset: offset,
);
switch (result) {
case Ok<NotificationResponseModel>():
_unreadNotificationResponse = result.value;
break;
case Error<NotificationResponseModel>():
_errorMessage = result.error.toString();
break;
}
_isUnreadLoading = false;
notifyListeners();
}
}