115 lines
3.1 KiB
Dart
115 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
final Map<String, MaterialColor> appColors = {
|
|
'Blue': Colors.blue,
|
|
'Green': Colors.green,
|
|
'Red': Colors.red,
|
|
'Purple': Colors.purple,
|
|
'Orange': Colors.orange,
|
|
'Teal': Colors.teal,
|
|
};
|
|
|
|
class ThemeNotifier with ChangeNotifier {
|
|
|
|
// 기본 테마 설정
|
|
ThemeData _themeData = ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
useMaterial3: true,
|
|
scaffoldBackgroundColor: Colors.grey[50],
|
|
appBarTheme: const AppBarTheme(
|
|
backgroundColor: Colors.white,
|
|
elevation: 0,
|
|
iconTheme: IconThemeData(color: Colors.black),
|
|
titleTextStyle: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
);
|
|
|
|
final String _themeKey = 'selected_theme';
|
|
final String _darkModeKey = 'is_dark_mode';
|
|
// 🔽 [신규] 폰트 크기 키
|
|
final String _textScaleKey = 'text_scale_factor';
|
|
|
|
MaterialColor _currentColor = Colors.blue;
|
|
bool _isDarkMode = false;
|
|
// 🔽 [신규] 폰트 배율 (기본 1.0)
|
|
double _textScaleFactor = 1.0;
|
|
|
|
ThemeData get currentTheme => ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: _currentColor,
|
|
brightness: Brightness.light,
|
|
),
|
|
useMaterial3: true,
|
|
brightness: Brightness.light,
|
|
);
|
|
|
|
ThemeData get currentDarkTheme => ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: _currentColor,
|
|
brightness: Brightness.dark,
|
|
),
|
|
useMaterial3: true,
|
|
brightness: Brightness.dark,
|
|
);
|
|
|
|
ThemeMode get currentThemeMode => _isDarkMode ? ThemeMode.dark : ThemeMode.light;
|
|
|
|
bool get isDarkMode => _isDarkMode;
|
|
MaterialColor get currentColor => _currentColor;
|
|
|
|
// 🔽 [신규] getter
|
|
double get textScaleFactor => _textScaleFactor;
|
|
|
|
ThemeNotifier() {
|
|
_loadTheme();
|
|
}
|
|
|
|
void _loadTheme() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
final themeName = prefs.getString(_themeKey) ?? 'Blue';
|
|
_currentColor = appColors[themeName] ?? Colors.blue;
|
|
|
|
_isDarkMode = prefs.getBool(_darkModeKey) ?? false;
|
|
|
|
// 🔽 [신규] 로드
|
|
_textScaleFactor = prefs.getDouble(_textScaleKey) ?? 1.0;
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
// [Fix] main.dart에서 호출하는 메서드 추가
|
|
ThemeData getTheme() => _themeData;
|
|
|
|
void setTheme(String themeName) async {
|
|
final newColor = appColors[themeName];
|
|
if (newColor == null) return;
|
|
|
|
_currentColor = newColor;
|
|
notifyListeners();
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
prefs.setString(_themeKey, themeName);
|
|
}
|
|
|
|
void toggleTheme(bool isDark) async {
|
|
_isDarkMode = isDark;
|
|
notifyListeners();
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
prefs.setBool(_darkModeKey, isDark);
|
|
}
|
|
|
|
// 🔽 [신규] 폰트 크기 변경
|
|
void setTextScale(double scale) async {
|
|
_textScaleFactor = scale;
|
|
notifyListeners();
|
|
final prefs = await SharedPreferences.getInstance();
|
|
prefs.setDouble(_textScaleKey, scale);
|
|
}
|
|
} |