Files
SpotiFLAC-Mobile/lib/providers/theme_provider.dart
T
zarzet 63e1a9b9c8 feat(ui): add Mornye glass theme and adaptive music player
Add a selectable Mornye theme with shared glass controls, dialogs, sheets, notifications, and collection headers while retaining Material components.

Update player artwork, lyrics transitions and highlighting, synchronized rolling time labels, volume controls, and compact navigation. Unify metadata, Library, search, and extension surfaces; preserve restored artwork and report extension load failures.

Validation: full Flutter analyzer clean; 713 tests passed and 4 skipped; pinned Dart formatting and diff checks passed; signed ARM64 and ARM32 release APKs built and verified.
2026-09-19 12:10:10 +07:00

96 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:spotiflac_android/models/theme_settings.dart';
final initialThemeSettingsProvider = Provider<ThemeSettings>(
(ref) => const ThemeSettings(),
);
ThemeSettings loadBootstrapThemeSettings(SharedPreferences prefs) {
return ThemeSettings(
themeMode: themeModeFromString(prefs.getString(kThemeModeKey)),
useDynamicColor: prefs.getBool(kUseDynamicColorKey) ?? true,
seedColorValue: prefs.getInt(kSeedColorKey) ?? kDefaultSeedColor,
useAmoled: prefs.getBool(kUseAmoledKey) ?? false,
style: themeStyleFromString(prefs.getString(kThemeStyleKey)),
);
}
final themeProvider = NotifierProvider<ThemeNotifier, ThemeSettings>(() {
return ThemeNotifier();
});
class ThemeNotifier extends Notifier<ThemeSettings> {
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
@override
ThemeSettings build() {
_loadFromStorage();
return ref.read(initialThemeSettingsProvider);
}
Future<void> _loadFromStorage() async {
try {
final prefs = await _prefs;
final modeString = prefs.getString(kThemeModeKey);
final useDynamic = prefs.getBool(kUseDynamicColorKey);
final seedColor = prefs.getInt(kSeedColorKey);
final useAmoled = prefs.getBool(kUseAmoledKey);
state = ThemeSettings(
themeMode: themeModeFromString(modeString),
useDynamicColor: useDynamic ?? true,
seedColorValue: seedColor ?? kDefaultSeedColor,
useAmoled: useAmoled ?? false,
style: themeStyleFromString(prefs.getString(kThemeStyleKey)),
);
} catch (e) {
debugPrint('Error loading theme settings: $e');
}
}
Future<void> _saveToStorage() async {
try {
final prefs = await _prefs;
await prefs.setString(kThemeModeKey, state.themeMode.name);
await prefs.setBool(kUseDynamicColorKey, state.useDynamicColor);
await prefs.setInt(kSeedColorKey, state.seedColorValue);
await prefs.setBool(kUseAmoledKey, state.useAmoled);
await prefs.setString(kThemeStyleKey, state.style.name);
} catch (e) {
debugPrint('Error saving theme settings: $e');
}
}
Future<void> setThemeMode(ThemeMode mode) async {
state = state.copyWith(themeMode: mode);
await _saveToStorage();
}
Future<void> setStyle(AppThemeStyle style) async {
state = state.copyWith(style: style);
await _saveToStorage();
}
Future<void> setUseDynamicColor(bool value) async {
state = state.copyWith(useDynamicColor: value);
await _saveToStorage();
}
Future<void> setSeedColor(Color color) async {
state = state.copyWith(seedColorValue: color.toARGB32());
await _saveToStorage();
}
Future<void> setSeedColorValue(int colorValue) async {
state = state.copyWith(seedColorValue: colorValue);
await _saveToStorage();
}
Future<void> setUseAmoled(bool value) async {
state = state.copyWith(useAmoled: value);
await _saveToStorage();
}
}