loadNotifications method
Future<void>
loadNotifications(
{ - bool refresh = false,
})
Implementation
Future<void> loadNotifications({bool refresh = false}) async {
if (state.isLoading) return;
final page = refresh ? 1 : state.currentPage;
state = state.copyWith(isLoading: true);
try {
final response = await _service.getNotifications(page: page);
final merged =
refresh ? response.data : [...state.notifications, ...response.data];
state = state.copyWith(
notifications: merged,
isLoading: false,
hasNextPage: response.hasNextPage,
currentPage: page + 1,
);
} catch (e) {
state = state.copyWith(isLoading: false, error: e.toString());
}
}