fixed pagination
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user