From e6ee83d9c25a3182d3d417d158ca69b642cec0c6 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Wed, 4 Mar 2026 16:33:45 +0100 Subject: [PATCH] fix: preserve home screen scroll position on back navigation --- lib/mixins/tab_visibility_aware.dart | 2 +- lib/screens/discover_screen.dart | 6 ++++-- lib/screens/main_screen.dart | 2 +- lib/services/plex_client.dart | 5 +---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/mixins/tab_visibility_aware.dart b/lib/mixins/tab_visibility_aware.dart index 28a4308b..a136ed67 100644 --- a/lib/mixins/tab_visibility_aware.dart +++ b/lib/mixins/tab_visibility_aware.dart @@ -3,6 +3,6 @@ /// Used by MainScreen to pause expensive work (e.g. animation tickers) /// when the screen's tab is no longer visible, and resume it when shown again. mixin TabVisibilityAware { - void onTabShown(); + void onTabShown({bool scrollToTop = true}); void onTabHidden(); } diff --git a/lib/screens/discover_screen.dart b/lib/screens/discover_screen.dart index 3b09e280..169b2f17 100644 --- a/lib/screens/discover_screen.dart +++ b/lib/screens/discover_screen.dart @@ -379,11 +379,13 @@ class _DiscoverScreenState extends State } @override - void onTabShown() { + void onTabShown({bool scrollToTop = true}) { if (!_isAutoScrollPaused) { _startAutoScroll(); } - _focusTopBoundary(); + if (scrollToTop) { + _focusTopBoundary(); + } } // Helper method to calculate visible dot range (max 5 dots) diff --git a/lib/screens/main_screen.dart b/lib/screens/main_screen.dart index 17a45386..21d5287d 100644 --- a/lib/screens/main_screen.dart +++ b/lib/screens/main_screen.dart @@ -796,7 +796,7 @@ class _MainScreenState extends State with RouteAware, WindowListener // Called when returning to this route from a child route (e.g., from video player) if (_currentIndex == 0 && !_isOffline) { if (_discoverKey.currentState case final TabVisibilityAware aware) { - aware.onTabShown(); + aware.onTabShown(scrollToTop: false); } _onDiscoverBecameVisible(); } diff --git a/lib/services/plex_client.dart b/lib/services/plex_client.dart index 859110e7..03f3f5d5 100644 --- a/lib/services/plex_client.dart +++ b/lib/services/plex_client.dart @@ -2,9 +2,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:isolate'; import 'dart:math'; -import 'dart:typed_data'; -import 'dart:ui' show VoidCallback; - import 'package:flutter/foundation.dart'; import 'package:dio/dio.dart'; @@ -146,7 +143,7 @@ class PlexClient { /// Custom response decoder that handles malformed UTF-8 gracefully. /// Large responses are decoded in a background isolate to avoid ANR. - static FutureOr _lenientUtf8Decoder(List responseBytes, RequestOptions _, ResponseBody __) { + static FutureOr _lenientUtf8Decoder(List responseBytes, RequestOptions _, ResponseBody _a) { if (responseBytes.length > 50 * 1024) { return compute(_decodeUtf8, responseBytes); }