fixed pagination

This commit is contained in:
llsajjad
2025-09-27 15:27:45 +03:30
parent ca81da026d
commit 1fdbff77a1
6 changed files with 57 additions and 57 deletions
+11 -5
View File
@@ -80,7 +80,8 @@ class NotificationViewModel with ChangeNotifier {
}
notifyListeners();
final int offset = (page - 1) * _pageSize;
final int offset = page * _pageSize;
final result = await _repository.getNotifications(
limit: _pageSize,
offset: offset,
@@ -89,10 +90,15 @@ class NotificationViewModel with ChangeNotifier {
switch (result) {
case Ok<NotificationResponseModel>():
final data = result.value;
if (isPagination && allNotificationResponse != null) {
final old = allNotificationResponse?.data ?? [];
final fresh = data.data ?? [];
allNotificationResponse = data.copyWith(data: [...old, ...fresh]);
allNotificationResponse = allNotificationResponse!.copyWith(
data: [...old, ...fresh],
meta: data.meta,
);
} else {
allNotificationResponse = data;
}
@@ -101,7 +107,7 @@ class NotificationViewModel with ChangeNotifier {
currentPageAll = page;
totalPagesAll = data.meta?.pages ?? 1;
hasMoreAll = (data.data?.length ?? 0) >= _pageSize;
hasMoreAll = currentPageAll < totalPagesAll;
break;
case Error<NotificationResponseModel>():
@@ -125,7 +131,7 @@ class NotificationViewModel with ChangeNotifier {
}
notifyListeners();
final int offset = (page - 1) * _pageSize;
final int offset = page * _pageSize;
final result = await _repository.getUnreadNotifications(
limit: _pageSize,
offset: offset,
@@ -168,7 +174,7 @@ class NotificationViewModel with ChangeNotifier {
}
notifyListeners();
final int offset = (page - 1) * _pageSize;
final int offset = page * _pageSize;
final result = await _repository.getImportantNotifications(
limit: _pageSize,