Fold scroll-to-top into _fetchPage

Replace the _goToPage wrapper with an optional scrollToTop flag on
_fetchPage, so there is a single fetch entry point. The pagination bar
passes scrollToTop: true; all other callers keep the current behaviour.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-06-04 10:12:36 -04:00
co-authored by Claude Opus 4.8
parent aa5f65de2b
commit 51dc5495ec
2 changed files with 16 additions and 24 deletions
+11 -15
View File
@@ -74,19 +74,6 @@ class _DeviceListState extends State<DeviceList> with RouteAware {
super.dispose(); super.dispose();
} }
/// Fetches [page] and scrolls back to the top of the list, so changing pages
/// always starts the new page from its first row.
void _goToPage(int page) {
if (_scrollController.hasClients) {
_scrollController.animateTo(
0,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
);
}
_fetchPage(page);
}
void _onOwnerChanged() { void _onOwnerChanged() {
_ownerDebounce?.cancel(); _ownerDebounce?.cancel();
_ownerDebounce = Timer( _ownerDebounce = Timer(
@@ -95,7 +82,16 @@ class _DeviceListState extends State<DeviceList> with RouteAware {
); );
} }
Future<void> _fetchPage(int page) async { /// Fetches [page]. When [scrollToTop] is set, the list animates back to its
/// first row, so changing pages always starts the new page from the top.
Future<void> _fetchPage(int page, {bool scrollToTop = false}) async {
if (scrollToTop && _scrollController.hasClients) {
_scrollController.animateTo(
0,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
);
}
_fetchToken?.cancel(); _fetchToken?.cancel();
final token = CancelToken(); final token = CancelToken();
_fetchToken = token; _fetchToken = token;
@@ -339,7 +335,7 @@ class _DeviceListState extends State<DeviceList> with RouteAware {
currentPage: _currentPage, currentPage: _currentPage,
hasNextPage: _hasNextPage, hasNextPage: _hasNextPage,
isLoading: _isLoading, isLoading: _isLoading,
onPageChanged: _goToPage, onPageChanged: (page) => _fetchPage(page, scrollToTop: true),
), ),
), ),
], ],
+5 -9
View File
@@ -112,20 +112,16 @@ class _NotificationsListState extends State<NotificationsList>
super.dispose(); super.dispose();
} }
/// Fetches [page] and scrolls back to the top of the list, so changing pages /// Fetches [page]. When [scrollToTop] is set, the list animates back to its
/// always starts the new page from its first item. /// first item, so changing pages always starts the new page from the top.
void _goToPage(int page) { Future<void> _fetchPage(int page, {bool scrollToTop = false}) async {
if (_scrollController.hasClients) { if (scrollToTop && _scrollController.hasClients) {
_scrollController.animateTo( _scrollController.animateTo(
0, 0,
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
curve: Curves.easeOut, curve: Curves.easeOut,
); );
} }
_fetchPage(page);
}
Future<void> _fetchPage(int page) async {
_fetchToken?.cancel(); _fetchToken?.cancel();
final token = CancelToken(); final token = CancelToken();
_fetchToken = token; _fetchToken = token;
@@ -312,7 +308,7 @@ class _NotificationsListState extends State<NotificationsList>
currentPage: _currentPage, currentPage: _currentPage,
hasNextPage: _hasNextPage, hasNextPage: _hasNextPage,
isLoading: _isLoading, isLoading: _isLoading,
onPageChanged: _goToPage, onPageChanged: (page) => _fetchPage(page, scrollToTop: true),
), ),
), ),
]; ];