atles / lib /providers /theme_provider.dart
spartan8806's picture
ATLES codebase - Source code only
99b8067
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; // Default to dark theme (ATLES style)
ThemeMode get themeMode => _themeMode;
// ATLES Dark Theme
ThemeData get darkTheme => ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorScheme: const ColorScheme.dark(
primary: Color(0xFF00D4FF), // ATLES cyan
secondary: Color(0xFF7C4DFF), // ATLES purple
surface: Color(0xFF1A1A1A), // Dark background
background: Color(0xFF121212), // Darker background
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)),
),
),
);
// ATLES Light Theme
ThemeData get lightTheme => ThemeData(
useMaterial3: true,
brightness: Brightness.light,
colorScheme: const ColorScheme.light(
primary: Color(0xFF0066CC), // ATLES blue
secondary: Color(0xFF6200EA), // ATLES purple
surface: Color(0xFFF5F5F5), // Light background
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; // Default to dark
_themeMode = ThemeMode.values[themeIndex];
notifyListeners();
}
Future<void> _saveTheme() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_themeKey, _themeMode.index);
}
}