fixes to scrubbing and offline issues

This commit is contained in:
Forrest 2026-07-31 21:06:19 -04:00
parent 5bf85a5f44
commit d558aba246
31 changed files with 296 additions and 33 deletions

View file

@ -21,7 +21,8 @@ class AppShell extends ConsumerStatefulWidget {
ConsumerState<AppShell> createState() => _AppShellState();
}
class _AppShellState extends ConsumerState<AppShell> {
class _AppShellState extends ConsumerState<AppShell>
with WidgetsBindingObserver {
static const _tabs = ['Home', 'Browse', 'Now Playing'];
// Home and Browse push detail screens, so each owns a nested Navigator whose
@ -38,6 +39,7 @@ class _AppShellState extends ConsumerState<AppShell> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
ref.listenManual<AppSettings>(settingsProvider, (prev, next) {
if (_browseSeeded) return;
_browseSeeded = true;
@ -45,6 +47,23 @@ class _AppShellState extends ConsumerState<AppShell> {
});
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
// Returning to the foreground: re-read authoritative position/duration from
// the player, which can go stale while backgrounded or across an audio
// interruption and otherwise leaves the playhead frozen (see
// PlaybackController.resyncFromPlayer).
if (state == AppLifecycleState.resumed) {
ref.read(playbackProvider.notifier).resyncFromPlayer();
}
}
GlobalKey<NavigatorState>? _navKeyForTab(int tab) => switch (tab) {
0 => _homeNavKey,
1 => _browseNavKey,