This commit is contained in:
2025-08-06 17:26:25 +05:30
parent 2fdef7c850
commit c4d4261afc
33 changed files with 772 additions and 935 deletions

View File

@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:kmobile/config/theme_type.dart';
class ThemeController with ChangeNotifier {
ThemeType _currentTheme = ThemeType.violet;
ThemeType get currentTheme => _currentTheme;
Future<void> loadTheme() async {
final prefs = await SharedPreferences.getInstance();
final savedTheme = prefs.getString('color_theme');
if (savedTheme != null) {
_currentTheme = ThemeType.values.firstWhere(
(e) => e.name == savedTheme,
orElse: () => ThemeType.violet,
);
notifyListeners();
}
}
Future<void> setTheme(ThemeType theme) async {
_currentTheme = theme;
notifyListeners();
final prefs = await SharedPreferences.getInstance();
await prefs.setString('color_theme', theme.name);
}
}

View File

@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ThemeModeController with ChangeNotifier {
ThemeMode _currentThemeMode = ThemeMode.system;
ThemeMode get currentThemeMode => _currentThemeMode;
Future<void> loadThemeMode() async {
final prefs = await SharedPreferences.getInstance();
final savedMode = prefs.getString('theme_mode');
if (savedMode != null) {
switch (savedMode) {
case 'light':
_currentThemeMode = ThemeMode.light;
break;
case 'dark':
_currentThemeMode = ThemeMode.dark;
break;
default:
_currentThemeMode = ThemeMode.system;
}
notifyListeners();
}
}
Future<void> toggleThemeMode() async {
if (_currentThemeMode == ThemeMode.light) {
_currentThemeMode = ThemeMode.dark;
} else {
_currentThemeMode = ThemeMode.light;
}
notifyListeners();
final prefs = await SharedPreferences.getInstance();
await prefs.setString(
'theme_mode',
_currentThemeMode == ThemeMode.light ? 'light' : 'dark',
);
}
}

View File

@@ -0,0 +1,6 @@
enum ThemeType {
violet,
green,
orange,
blue,
}

View File

@@ -1,266 +1,95 @@
/*class AppThemes {
static ThemeData getLightTheme(ThemeType type) {
switch (type) {
case ThemeType.green:
return ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.green,
scaffoldBackgroundColor: Colors.white,
);
case ThemeType.orange:
return ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.orange,
scaffoldBackgroundColor: Colors.white,
);
case ThemeType.blue:
return ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.blue,
scaffoldBackgroundColor: Colors.white,
);
case ThemeType.violet:
default:
return ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.deepPurple,
scaffoldBackgroundColor: Colors.white,
);
}
}
static ThemeData getDarkTheme(ThemeType type) {
switch (type) {
case ThemeType.green:
return ThemeData(
brightness: Brightness.dark,
primarySwatch: Colors.green,
scaffoldBackgroundColor: Colors.black,
);
case ThemeType.orange:
return ThemeData(
brightness: Brightness.dark,
primarySwatch: Colors.orange,
scaffoldBackgroundColor: Colors.black,
);
case ThemeType.blue:
return ThemeData(
brightness: Brightness.dark,
primarySwatch: Colors.blue,
scaffoldBackgroundColor: Colors.black,
);
case ThemeType.violet:
default:
return ThemeData(
brightness: Brightness.dark,
primarySwatch: Colors.deepPurple,
scaffoldBackgroundColor: Colors.black,
);
}
}
}*/
import 'package:flutter/material.dart';
import 'theme_type.dart';
class AppThemes {
// Private constructor to prevent instantiation
AppThemes._();
static ThemeData getLightTheme(ThemeType type) {
switch (type) {
case ThemeType.green:
return ThemeData(primarySwatch: Colors.green);
case ThemeType.orange:
return ThemeData(primarySwatch: Colors.orange);
case ThemeType.blue:
return ThemeData(primarySwatch: Colors.blue);
case ThemeType.violet:
default:
return ThemeData(primarySwatch: Colors.deepPurple);
}
}
// Light theme colors
static const Color _primaryColorLight = Color(0xFF1E88E5); // Blue 600
static const Color _secondaryColorLight = Color(0xFF26A69A); // Teal 400
static const Color _errorColorLight = Color(0xFFE53935); // Red 600
static const Color _surfaceColorLight = Colors.white;
// Dark theme colors
static const Color _primaryColorDark = Color(0xFF42A5F5); // Blue 400
static const Color _secondaryColorDark = Color(0xFF4DB6AC); // Teal 300
static const Color _errorColorDark = Color(0xFFEF5350); // Red 400
static const Color _surfaceColorDark = Color(0xFF1E1E1E);
// Text themes
static const TextTheme _textThemeLight = TextTheme(
displayLarge: TextStyle(
fontSize: 96,
fontWeight: FontWeight.w300,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
displayMedium: TextStyle(
fontSize: 60,
fontWeight: FontWeight.w300,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
displaySmall: TextStyle(
fontSize: 48,
fontWeight: FontWeight.w400,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
headlineMedium: TextStyle(
fontSize: 34,
fontWeight: FontWeight.w400,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
headlineSmall: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w400,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
titleLarge: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
bodyLarge: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
bodyMedium: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
bodySmall: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Color(0xFF757575),
fontFamily: 'Rubik',
),
labelLarge: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Color(0xFF212121),
fontFamily: 'Rubik',
),
);
static final TextTheme _textThemeDark = _textThemeLight.copyWith(
displayLarge: _textThemeLight.displayLarge?.copyWith(color: Colors.white),
displayMedium: _textThemeLight.displayMedium?.copyWith(color: Colors.white),
displaySmall: _textThemeLight.displaySmall?.copyWith(color: Colors.white),
headlineMedium:
_textThemeLight.headlineMedium?.copyWith(color: Colors.white),
headlineSmall: _textThemeLight.headlineSmall?.copyWith(color: Colors.white),
titleLarge: _textThemeLight.titleLarge?.copyWith(color: Colors.white),
bodyLarge: _textThemeLight.bodyLarge?.copyWith(color: Colors.white),
bodyMedium: _textThemeLight.bodyMedium?.copyWith(color: Colors.white),
bodySmall: _textThemeLight.bodySmall?.copyWith(color: Colors.white70),
labelLarge: _textThemeLight.labelLarge?.copyWith(color: Colors.white),
);
// Light theme
static final ThemeData lightTheme = ThemeData(
useMaterial3: true,
fontFamily: 'Rubik',
colorScheme: const ColorScheme.light(
primary: _primaryColorLight,
secondary: _secondaryColorLight,
error: _errorColorLight,
surface: _surfaceColorLight,
onPrimary: Colors.white,
onSecondary: Colors.white,
onSurface: Colors.black87,
onError: Colors.white,
brightness: Brightness.light,
),
textTheme: _textThemeLight,
appBarTheme: const AppBarTheme(
elevation: 0,
backgroundColor: _surfaceColorLight,
foregroundColor: Color(0xFF212121),
centerTitle: true,
),
cardTheme: CardTheme(
//Earlier CardThemeData
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: _primaryColorLight,
elevation: 2,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: _primaryColorLight,
side: const BorderSide(color: _primaryColorLight),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: _primaryColorLight,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: Colors.grey[100],
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: Colors.grey[300]!),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(color: _primaryColorLight, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(color: _errorColorLight, width: 2),
),
labelStyle: const TextStyle(color: Colors.grey),
),
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
selectedItemColor: _primaryColorLight,
unselectedItemColor: Colors.grey,
),
);
// Dark theme
static final ThemeData darkTheme = ThemeData(
fontFamily: 'Rubik',
useMaterial3: true,
colorScheme: const ColorScheme.dark(
primary: _primaryColorDark,
secondary: _secondaryColorDark,
error: _errorColorDark,
surface: _surfaceColorDark,
onPrimary: Colors.black,
onSecondary: Colors.black,
onSurface: Colors.white,
onError: Colors.black,
brightness: Brightness.dark,
),
textTheme: _textThemeDark,
appBarTheme: const AppBarTheme(
elevation: 0,
backgroundColor: _surfaceColorDark,
foregroundColor: Colors.white,
centerTitle: true,
),
cardTheme: CardTheme(
//Earlier was CardThemeData
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
color: const Color(0xFF2C2C2C),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.black,
backgroundColor: _primaryColorDark,
elevation: 2,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: _primaryColorDark,
side: const BorderSide(color: _primaryColorDark),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: _primaryColorDark,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: const Color(0xFF2A2A2A),
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(color: Color(0xFF3A3A3A)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(color: _primaryColorDark, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(color: _errorColorDark, width: 2),
),
labelStyle: const TextStyle(color: Colors.grey),
),
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
selectedItemColor: _primaryColorDark,
unselectedItemColor: Colors.grey,
backgroundColor: _surfaceColorDark,
),
);
}
static ThemeData getDarkTheme(ThemeType type) {
switch (type) {
case ThemeType.green:
return ThemeData.dark().copyWith(primaryColor: Colors.green);
case ThemeType.orange:
return ThemeData.dark().copyWith(primaryColor: Colors.orange);
case ThemeType.blue:
return ThemeData.dark().copyWith(primaryColor: Colors.blue);
case ThemeType.violet:
default:
return ThemeData.dark().copyWith(primaryColor: Colors.deepPurple);
}
}
}