| import 'package:flutter/material.dart'; |
| import 'package:shared_preferences/shared_preferences.dart'; |
|
|
| class ThemeProvider extends ChangeNotifier { |
| static const String _themeKey = 'theme_mode'; |
| |
| ThemeMode _themeMode = ThemeMode.dark; |
| |
| ThemeMode get themeMode => _themeMode; |
| |
| |
| ThemeData get darkTheme => ThemeData( |
| useMaterial3: true, |
| brightness: Brightness.dark, |
| colorScheme: const ColorScheme.dark( |
| primary: Color(0xFF00D4FF), |
| secondary: Color(0xFF7C4DFF), |
| surface: Color(0xFF1A1A1A), |
| background: Color(0xFF121212), |
| onPrimary: Colors.black, |
| onSecondary: Colors.white, |
| onSurface: Colors.white, |
| onBackground: Colors.white, |
| ), |
| appBarTheme: const AppBarTheme( |
| backgroundColor: Color(0xFF1A1A1A), |
| foregroundColor: Colors.white, |
| elevation: 0, |
| ), |
| cardTheme: CardTheme( |
| color: const Color(0xFF2A2A2A), |
| elevation: 4, |
| shape: RoundedRectangleBorder( |
| borderRadius: BorderRadius.circular(12), |
| ), |
| ), |
| elevatedButtonTheme: ElevatedButtonThemeData( |
| style: ElevatedButton.styleFrom( |
| backgroundColor: const Color(0xFF00D4FF), |
| foregroundColor: Colors.black, |
| shape: RoundedRectangleBorder( |
| borderRadius: BorderRadius.circular(8), |
| ), |
| ), |
| ), |
| inputDecorationTheme: InputDecorationTheme( |
| filled: true, |
| fillColor: const Color(0xFF2A2A2A), |
| border: OutlineInputBorder( |
| borderRadius: BorderRadius.circular(8), |
| borderSide: BorderSide.none, |
| ), |
| focusedBorder: OutlineInputBorder( |
| borderRadius: BorderRadius.circular(8), |
| borderSide: const BorderSide(color: Color(0xFF00D4FF)), |
| ), |
| ), |
| ); |
| |
| |
| ThemeData get lightTheme => ThemeData( |
| useMaterial3: true, |
| brightness: Brightness.light, |
| colorScheme: const ColorScheme.light( |
| primary: Color(0xFF0066CC), |
| secondary: Color(0xFF6200EA), |
| surface: Color(0xFFF5F5F5), |
| background: Colors.white, |
| onPrimary: Colors.white, |
| onSecondary: Colors.white, |
| onSurface: Colors.black, |
| onBackground: Colors.black, |
| ), |
| appBarTheme: const AppBarTheme( |
| backgroundColor: Color(0xFFF5F5F5), |
| foregroundColor: Colors.black, |
| elevation: 0, |
| ), |
| cardTheme: CardTheme( |
| color: Colors.white, |
| elevation: 2, |
| shape: RoundedRectangleBorder( |
| borderRadius: BorderRadius.circular(12), |
| ), |
| ), |
| elevatedButtonTheme: ElevatedButtonThemeData( |
| style: ElevatedButton.styleFrom( |
| backgroundColor: const Color(0xFF0066CC), |
| foregroundColor: Colors.white, |
| shape: RoundedRectangleBorder( |
| borderRadius: BorderRadius.circular(8), |
| ), |
| ), |
| ), |
| inputDecorationTheme: InputDecorationTheme( |
| filled: true, |
| fillColor: const Color(0xFFF5F5F5), |
| border: OutlineInputBorder( |
| borderRadius: BorderRadius.circular(8), |
| borderSide: BorderSide.none, |
| ), |
| focusedBorder: OutlineInputBorder( |
| borderRadius: BorderRadius.circular(8), |
| borderSide: const BorderSide(color: Color(0xFF0066CC)), |
| ), |
| ), |
| ); |
| |
| ThemeProvider() { |
| _loadTheme(); |
| } |
| |
| void toggleTheme() { |
| _themeMode = _themeMode == ThemeMode.dark |
| ? ThemeMode.light |
| : ThemeMode.dark; |
| _saveTheme(); |
| notifyListeners(); |
| } |
| |
| void setTheme(ThemeMode mode) { |
| _themeMode = mode; |
| _saveTheme(); |
| notifyListeners(); |
| } |
| |
| Future<void> _loadTheme() async { |
| final prefs = await SharedPreferences.getInstance(); |
| final themeIndex = prefs.getInt(_themeKey) ?? 2; |
| _themeMode = ThemeMode.values[themeIndex]; |
| notifyListeners(); |
| } |
| |
| Future<void> _saveTheme() async { |
| final prefs = await SharedPreferences.getInstance(); |
| await prefs.setInt(_themeKey, _themeMode.index); |
| } |
| } |
|
|