fix: library density migration crash on upgrade

close #812
This commit is contained in:
edde746
2026-04-07 00:19:27 +02:00
parent 928206a179
commit de1b37b7e9
+13 -4
View File
@@ -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,