Fold pagination +1 trick into API methods, return typed records

Remove dead _pageSize from BackendAPI and centralise the
"fetch perPage+1, detect hasNextPage, trim" logic into
listDevices and listNotifications. Both methods now accept
page/perPage and return ({items, hasNextPage}) records,
eliminating the duplicated boilerplate at each call site.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-31 17:40:18 -04:00
co-authored by Claude Sonnet 4.6
parent f75d1ce313
commit 8be65f3ffa
3 changed files with 34 additions and 29 deletions
+5 -5
View File
@@ -115,17 +115,17 @@ class _NotificationsListState extends State<NotificationsList>
_error = null;
});
try {
final results = await BackendAPI.instance.listNotifications(
final result = await BackendAPI.instance.listNotifications(
_filter.isNew,
page * _pageSize,
limit: _pageSize + 1,
page: page,
perPage: _pageSize,
cancelToken: token,
);
if (!mounted || token != _fetchToken) return;
setState(() {
_currentPage = page;
_hasNextPage = results.length > _pageSize;
_items = _hasNextPage ? results.take(_pageSize).toList() : results;
_hasNextPage = result.hasNextPage;
_items = result.items;
_isLoading = false;
});
} catch (e) {