tetraq/lib/core/theme_manager.dart

66 lines
2.2 KiB
Dart
Raw Normal View History

2026-03-04 21:00:00 +01:00
// ===========================================================================
// FILE: lib/core/theme_manager.dart
// ===========================================================================
2026-02-27 23:35:54 +01:00
import 'package:flutter/material.dart';
2026-03-15 17:00:01 +01:00
import 'package:flutter/services.dart';
2026-02-27 23:35:54 +01:00
import 'app_colors.dart';
import '../services/storage_service.dart';
2026-03-15 17:00:01 +01:00
// --- ENUM DEI TEMI AGGIORNATO ---
const Map<AppThemeType, IconData> themeIcons = {
AppThemeType.cyberpunk: Icons.electric_bolt,
AppThemeType.doodle: Icons.brush,
AppThemeType.music: Icons.headset_mic,
AppThemeType.arcade: Icons.videogame_asset,
AppThemeType.grimorio: Icons.auto_stories,
};
2026-02-27 23:35:54 +01:00
2026-03-15 17:00:01 +01:00
const Map<AppThemeType, String> themeNames = {
AppThemeType.cyberpunk: "Cyberpunk",
AppThemeType.doodle: "Doodle",
AppThemeType.music: "Music",
AppThemeType.arcade: "Arcade",
AppThemeType.grimorio: "Grimorio",
};
2026-03-04 21:00:00 +01:00
2026-03-15 17:00:01 +01:00
class ThemeManager with ChangeNotifier {
AppThemeType _currentThemeType = AppThemeType.doodle;
ThemeColors _currentColors = AppColors.getTheme(AppThemeType.doodle);
2026-02-27 23:35:54 +01:00
AppThemeType get currentThemeType => _currentThemeType;
2026-03-15 17:00:01 +01:00
ThemeColors get currentColors => _currentColors;
2026-02-27 23:35:54 +01:00
2026-03-15 17:00:01 +01:00
ThemeManager() {
_loadTheme();
}
2026-03-04 21:00:00 +01:00
2026-03-15 17:00:01 +01:00
void _loadTheme() async {
String themeStr = StorageService.instance.getTheme();
AppThemeType loadedType = AppThemeType.values.firstWhere(
(e) => e.toString() == themeStr,
orElse: () => AppThemeType.doodle
);
_currentThemeType = loadedType;
_currentColors = AppColors.getTheme(loadedType);
_updateSystemUI();
notifyListeners();
}
2026-03-04 21:00:00 +01:00
2026-03-15 17:00:01 +01:00
void setTheme(AppThemeType type) {
_currentThemeType = type;
_currentColors = AppColors.getTheme(type);
StorageService.instance.saveTheme(type.toString());
_updateSystemUI();
2026-02-27 23:35:54 +01:00
notifyListeners();
}
2026-03-15 17:00:01 +01:00
void _updateSystemUI() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: _currentThemeType == AppThemeType.doodle ? Brightness.dark : Brightness.light,
systemNavigationBarColor: _currentColors.background,
systemNavigationBarIconBrightness: _currentThemeType == AppThemeType.doodle ? Brightness.dark : Brightness.light,
));
}
2026-02-27 23:35:54 +01:00
}