From 747dbdb46f442cc2252aac1538f999f504a78c66 Mon Sep 17 00:00:00 2001 From: Dr-Blank <64108942+Dr-Blank@users.noreply.github.com> Date: Sat, 5 Oct 2024 21:02:14 -0400 Subject: [PATCH] fix: bad state when reading player for theme and new login --- lib/main.dart | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0da35ae..6020a6a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -83,26 +83,32 @@ class MyApp extends ConsumerWidget { } if (themeSettings.useCurrentPlayerThemeThroughoutApp) { - final player = ref.watch(audiobookPlayerProvider); - if (player.book != null) { - final themeLight = ref.watch( - themeOfLibraryItemProvider( - player.book!.libraryItemId, - highContrast: shouldUseHighContrast, - brightness: Brightness.light, - ), - ); - final themeDark = ref.watch( - themeOfLibraryItemProvider( - player.book!.libraryItemId, - highContrast: shouldUseHighContrast, - brightness: Brightness.dark, - ), - ); - if (themeLight.valueOrNull != null && themeDark.valueOrNull != null) { - lightColorScheme = themeLight.valueOrNull!; - darkColorScheme = themeDark.valueOrNull!; + try { + final player = ref.watch(audiobookPlayerProvider); + if (player.book != null) { + final themeLight = ref.watch( + themeOfLibraryItemProvider( + player.book!.libraryItemId, + highContrast: shouldUseHighContrast, + brightness: Brightness.light, + ), + ); + final themeDark = ref.watch( + themeOfLibraryItemProvider( + player.book!.libraryItemId, + highContrast: shouldUseHighContrast, + brightness: Brightness.dark, + ), + ); + if (themeLight.valueOrNull != null && themeDark.valueOrNull != null) { + lightColorScheme = themeLight.valueOrNull!; + darkColorScheme = themeDark.valueOrNull!; + } } + } catch (e) { + debugPrintStack(stackTrace: StackTrace.current, label: e.toString()); + appLogger.severe('not building with player theme'); + appLogger.severe(e.toString()); } } final appThemeLight = ThemeData( @@ -129,6 +135,8 @@ class MyApp extends ConsumerWidget { ); } catch (e) { debugPrintStack(stackTrace: StackTrace.current, label: e.toString()); + appLogger.severe(e.toString()); + if (needOnboarding) { routerConfig.goNamed(Routes.onboarding.name); } @@ -155,6 +163,7 @@ class _EagerInitialization extends ConsumerWidget { ref.watch(shakeDetectorProvider); } catch (e) { debugPrintStack(stackTrace: StackTrace.current, label: e.toString()); + appLogger.severe(e.toString()); } return child;