store lastUsedColor as int

This commit is contained in:
Adam Velebil 2024-01-24 13:01:39 +01:00
parent 2c4ac862fa
commit d56166b6ca
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10

View File

@ -54,22 +54,6 @@ extension on Application {
};
}
extension on String? {
Color? asColor() {
final hexValue = this;
if (hexValue == null) {
return null;
}
final intValue = int.tryParse(hexValue, radix: 16);
if (intValue == null) {
return null;
}
return Color(intValue);
}
}
List<Application> Function(Ref) implementedApps(List<Application> apps) =>
(ref) {
final hasFeature = ref.watch(featureProvider);
@ -198,9 +182,9 @@ class ThemeNotifier extends Notifier<ThemeData> {
primaryColor = customization?.color ?? color;
if (primaryColor != null) {
// remember the last used color
prefs.setString(
prefs.setInt(
prefLastUsedColor,
primaryColor.value.toRadixString(16),
primaryColor.value,
);
} else {
// the current color is null -> remove the last used color preference
@ -209,8 +193,10 @@ class ThemeNotifier extends Notifier<ThemeData> {
}
}
primaryColor ??= prefs.getString(prefLastUsedColor).asColor();
primaryColor ??= ref.read(primaryColorProvider);
final lastUsedColor = prefs.getInt(prefLastUsedColor);
primaryColor ??= lastUsedColor != null
? Color(lastUsedColor)
: ref.read(primaryColorProvider);
return (primaryColor != null)
? _getDefault(themeMode).copyWith(