This commit is contained in:
2026-03-26 13:46:23 +03:00
parent 87431a9fc9
commit 2d5eb92cba
7 changed files with 243 additions and 66 deletions
+51 -11
View File
@@ -6,7 +6,9 @@ enum GradientType { linear, linearReverse, radial, sweep, solid }
class CardColorService {
static const _key1 = 'card_color_primary';
static const _key2 = 'card_color_secondary';
static const _keyGradient = 'card_gradient_type';
static const _keyGradientLegacy = 'card_gradient_type';
static const _keyGradientLight = 'gradient_type_light';
static const _keyGradientDark = 'gradient_type_dark';
static const defaultPrimary = Color(0xFFBEF264);
static const defaultSecondary = Color(0xFF4D7C0F);
@@ -14,48 +16,86 @@ class CardColorService {
static const defaultPrimaryLight = Color(0xFF6A6482);
static const defaultSecondaryLight = Color(0xFF000000);
static const defaultGradient = GradientType.radial;
static const defaultGradientLight = GradientType.sweep;
static const defaultGradientDark = GradientType.radial;
static Future<(Color, Color, GradientType)> load({int? accountId}) async {
static Future<(Color, Color, GradientType, GradientType)> load({
int? accountId,
}) async {
final prefs = await SharedPreferences.getInstance();
final key1 = accountId != null ? '${_key1}_$accountId' : _key1;
final key2 = accountId != null ? '${_key2}_$accountId' : _key2;
final keyG = accountId != null ? '${_keyGradient}_$accountId' : _keyGradient;
final keyGLight = accountId != null
? '${_keyGradientLight}_$accountId'
: _keyGradientLight;
final keyGDark = accountId != null
? '${_keyGradientDark}_$accountId'
: _keyGradientDark;
final keyGLegacy = accountId != null
? '${_keyGradientLegacy}_$accountId'
: _keyGradientLegacy;
final c1 = prefs.getInt(key1);
final c2 = prefs.getInt(key2);
final g = prefs.getInt(keyG);
final legacyIndex = prefs.getInt(keyGLegacy);
GradientType parseWithDefault(int? index, GradientType fallback) {
if (index == null) return fallback;
final parsed = GradientType.values.elementAtOrNull(index);
return parsed ?? fallback;
}
final lightIndex = prefs.getInt(keyGLight);
final darkIndex = prefs.getInt(keyGDark);
return (
c1 != null ? Color(c1) : defaultPrimary,
c2 != null ? Color(c2) : defaultSecondary,
g != null ? GradientType.values[g] : defaultGradient,
parseWithDefault(lightIndex ?? legacyIndex, defaultGradientLight),
parseWithDefault(darkIndex ?? legacyIndex, defaultGradientDark),
);
}
static Future<void> save(
Color primary,
Color secondary,
GradientType gradient, {
GradientType lightGradient,
GradientType darkGradient, {
int? accountId,
}) async {
final prefs = await SharedPreferences.getInstance();
final key1 = accountId != null ? '${_key1}_$accountId' : _key1;
final key2 = accountId != null ? '${_key2}_$accountId' : _key2;
final keyG = accountId != null ? '${_keyGradient}_$accountId' : _keyGradient;
final keyGLight = accountId != null
? '${_keyGradientLight}_$accountId'
: _keyGradientLight;
final keyGDark = accountId != null
? '${_keyGradientDark}_$accountId'
: _keyGradientDark;
await prefs.setInt(key1, primary.value);
await prefs.setInt(key2, secondary.value);
await prefs.setInt(keyG, gradient.index);
await prefs.setInt(keyGLight, lightGradient.index);
await prefs.setInt(keyGDark, darkGradient.index);
}
static Future<void> reset(bool isDark, {int? accountId}) async {
final prefs = await SharedPreferences.getInstance();
final key1 = accountId != null ? '${_key1}_$accountId' : _key1;
final key2 = accountId != null ? '${_key2}_$accountId' : _key2;
final keyG = accountId != null ? '${_keyGradient}_$accountId' : _keyGradient;
final keyGLight = accountId != null
? '${_keyGradientLight}_$accountId'
: _keyGradientLight;
final keyGDark = accountId != null
? '${_keyGradientDark}_$accountId'
: _keyGradientDark;
final keyGLegacy = accountId != null
? '${_keyGradientLegacy}_$accountId'
: _keyGradientLegacy;
await prefs.remove(key1);
await prefs.remove(key2);
await prefs.remove(keyG);
await prefs.remove(keyGLight);
await prefs.remove(keyGDark);
await prefs.remove(keyGLegacy);
}
}