Added unread list api in notification
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user