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) => List<Application> Function(Ref) implementedApps(List<Application> apps) =>
(ref) { (ref) {
final hasFeature = ref.watch(featureProvider); final hasFeature = ref.watch(featureProvider);
@ -198,9 +182,9 @@ class ThemeNotifier extends Notifier<ThemeData> {
primaryColor = customization?.color ?? color; primaryColor = customization?.color ?? color;
if (primaryColor != null) { if (primaryColor != null) {
// remember the last used color // remember the last used color
prefs.setString( prefs.setInt(
prefLastUsedColor, prefLastUsedColor,
primaryColor.value.toRadixString(16), primaryColor.value,
); );
} else { } else {
// the current color is null -> remove the last used color preference // 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(); final lastUsedColor = prefs.getInt(prefLastUsedColor);
primaryColor ??= ref.read(primaryColorProvider); primaryColor ??= lastUsedColor != null
? Color(lastUsedColor)
: ref.read(primaryColorProvider);
return (primaryColor != null) return (primaryColor != null)
? _getDefault(themeMode).copyWith( ? _getDefault(themeMode).copyWith(