From de1b37b7e90338f371845ea2fe49f21baf339c86 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Tue, 7 Apr 2026 00:17:52 +0200 Subject: [PATCH] fix: library density migration crash on upgrade close #812 --- lib/services/settings_service.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/services/settings_service.dart b/lib/services/settings_service.dart index 00718e02..24f697e0 100644 --- a/lib/services/settings_service.dart +++ b/lib/services/settings_service.dart @@ -224,11 +224,20 @@ class SettingsService extends BaseSharedPreferencesService { } int getLibraryDensity() { - // New int format - final intVal = prefs.getInt(_keyLibraryDensity); - if (intVal != null) return intVal.clamp(LibraryDensity.min, LibraryDensity.max); + // New int format — getInt throws if the stored value is a different type + try { + final intVal = prefs.getInt(_keyLibraryDensity); + if (intVal != null) return intVal.clamp(LibraryDensity.min, LibraryDensity.max); + } on TypeError { + // Stored value is a String from old enum format — fall through to migration + } // Migrate from old enum string format - final strVal = prefs.getString(_keyLibraryDensity); + String? strVal; + try { + strVal = prefs.getString(_keyLibraryDensity); + } on TypeError { + // Value exists but isn't a String either + } final result = switch (strVal) { 'compact' => 2, 'comfortable' => 4,