Skip to content

Commit

Permalink
fix: bad state when reading player for theme and new login
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Blank committed Oct 6, 2024
1 parent e7205ed commit 747dbdb
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit 747dbdb

Please sign in to comment.