Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Cache cover seed color to prevent theme flash on restart

Nathan Poulson1cfbd54615ba
diff --git a/lib/main.dart b/lib/main.dart
index f8f14dc8..9e4d8d45 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -86,6 +86,18 @@ void main() async {
applyThemeMode(savedTheme);
snappyTransitionsNotifier.value = await PlayerSettings.getSnappyTransitions();
colorSourceNotifier.value = await PlayerSettings.getColorSource();
+ // Restore last cover seed color so the theme doesn't flash wallpaper colors
+ if (colorSourceNotifier.value == 'cover') {
+ final seedInt = await PlayerSettings.getCoverSeedColor();
+ if (seedInt != null) {
+ final seedColor = Color(seedInt);
+ coverSchemeNotifier.value = ColorScheme.fromSeed(
+ seedColor: seedColor,
+ brightness: parseThemeMode(await PlayerSettings.getThemeMode()) == ThemeMode.light
+ ? Brightness.light : Brightness.dark,
+ );
+ }
+ }
} catch (_) {}
// Capture Flutter framework errors (widget build failures, etc.)
@@ -366,9 +378,20 @@ class _AuthGateState extends State<AuthGate> {
await ScopedPrefs.migrateToScope();
// Reload settings that were read in main() before scope was active
- applyThemeMode(await PlayerSettings.getThemeMode());
+ final scopedTheme = await PlayerSettings.getThemeMode();
+ applyThemeMode(scopedTheme);
snappyTransitionsNotifier.value = await PlayerSettings.getSnappyTransitions();
colorSourceNotifier.value = await PlayerSettings.getColorSource();
+ if (colorSourceNotifier.value == 'cover') {
+ final seedInt = await PlayerSettings.getCoverSeedColor();
+ if (seedInt != null) {
+ coverSchemeNotifier.value = ColorScheme.fromSeed(
+ seedColor: Color(seedInt),
+ brightness: parseThemeMode(scopedTheme) == ThemeMode.light
+ ? Brightness.light : Brightness.dark,
+ );
+ }
+ }
// Start auth restoration immediately — it doesn't depend on audio/cast/
// download services and must not be blocked by a hanging service init.
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dart
index 040a86bf..96fe6569 100644
--- a/lib/screens/app_shell.dart
+++ b/lib/screens/app_shell.dart
@@ -205,6 +205,7 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Ticker
ColorScheme.fromImageProvider(provider: provider, brightness: brightness)
.then((scheme) {
coverSchemeNotifier.value = scheme;
+ PlayerSettings.setCoverSeedColor(scheme.primary.toARGB32());
}).catchError((_) {
// Image load failed - allow retry
_lastCoverItemId = null;
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index bac61f5d..839e2030 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -296,6 +296,11 @@ class PlayerSettings {
static Future<String> getColorSource() => _get('colorSource', 'wallpaper');
static Future<void> setColorSource(String value) => _set('colorSource', value);
+ /// Cached seed color from the last cover-art derivation, so we can show
+ /// the correct color immediately on restart without waiting for the image.
+ static Future<int?> getCoverSeedColor() async => await ScopedPrefs.getInt('coverSeedColor');
+ static Future<void> setCoverSeedColor(int value) => _set('coverSeedColor', value);
+
/// Check if an item has no audio content.
/// For minified responses (library list), duration == 0 means no audio files.
/// For full responses (detail sheet), we also check ebookFile + audioFiles.