petitspas/frontend/lib/theme/app_theme.dart

135 lines
5.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
enum ThemeType {
defaultTheme,
pastelTheme,
// Ajouter d'autres thèmes ici
}
class AppTheme extends ChangeNotifier {
static final AppTheme _instance = AppTheme._internal();
factory AppTheme() => _instance;
AppTheme._internal();
// Thème par défaut (P'titsPas)
static const Color _defaultPrimaryColor = Color(0xFF2B6CB0);
static const Color _defaultSecondaryColor = Color(0xFFF7FAFC);
static const Color _defaultBackgroundColor = Color(0xFFFFFFFF);
static const Color _defaultTextColor = Color(0xFF000000);
static const Color _defaultErrorColor = Color(0xFFF4A28C);
static const Color _defaultWarningColor = Color(0xFFF2D269);
static const Color _defaultSuccessColor = Color(0xFF4CAF50);
// Thème Pastel
static const Color _pastelPrimaryColor = Color(0xFF8AD0C8); // Turquoise
static const Color _pastelSecondaryColor = Color(0xFFC6A3D8); // Violet Pastel
static const Color _pastelBackgroundColor = Color(0xFFFFFEF9); // Ivoire BG
static const Color _pastelTextColor = Color(0xFF2F2F2F); // Encre
static const Color _pastelErrorColor = Color(0xFFFFB4AB); // Rose Pastel
static const Color _pastelWarningColor = Color(0xFFFFE4B5); // Jaune Pastel
static const Color _pastelSuccessColor = Color(0xFFA5D6A7); // Vert Pastel
// Configuration du thème actuel
ThemeType _currentTheme = ThemeType.defaultTheme;
ThemeType get currentTheme => _currentTheme;
// Getters pour les couleurs du thème actuel
Color get primaryColor => _currentTheme == ThemeType.defaultTheme ? _defaultPrimaryColor : _pastelPrimaryColor;
Color get secondaryColor => _currentTheme == ThemeType.defaultTheme ? _defaultSecondaryColor : _pastelSecondaryColor;
Color get backgroundColor => _currentTheme == ThemeType.defaultTheme ? _defaultBackgroundColor : _pastelBackgroundColor;
Color get textColor => _currentTheme == ThemeType.defaultTheme ? _defaultTextColor : _pastelTextColor;
Color get errorColor => _currentTheme == ThemeType.defaultTheme ? _defaultErrorColor : _pastelErrorColor;
Color get warningColor => _currentTheme == ThemeType.defaultTheme ? _defaultWarningColor : _pastelWarningColor;
Color get successColor => _currentTheme == ThemeType.defaultTheme ? _defaultSuccessColor : _pastelSuccessColor;
// Méthode pour changer de thème
void setTheme(ThemeType theme) {
_currentTheme = theme;
notifyListeners();
}
// Thème Material 3
ThemeData get lightTheme {
return ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.light(
primary: primaryColor,
secondary: secondaryColor,
background: backgroundColor,
error: errorColor,
tertiary: warningColor,
onPrimary: Colors.white,
onSecondary: Colors.white,
onBackground: textColor,
onError: Colors.white,
onTertiary: textColor,
),
scaffoldBackgroundColor: backgroundColor,
textTheme: TextTheme(
displayLarge: _getTitleStyle(32),
displayMedium: _getTitleStyle(28),
displaySmall: _getTitleStyle(24),
headlineMedium: _getTitleStyle(20),
headlineSmall: _getTitleStyle(18),
titleLarge: _getTitleStyle(16),
bodyLarge: _getBodyStyle(16),
bodyMedium: _getBodyStyle(14),
bodySmall: _getBodyStyle(12),
),
appBarTheme: AppBarTheme(
backgroundColor: primaryColor,
foregroundColor: Colors.white,
titleTextStyle: _getTitleStyle(20).copyWith(color: Colors.white),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: primaryColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: secondaryColor.withOpacity(0.5),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: primaryColor, width: 2),
),
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
),
snackBarTheme: SnackBarThemeData(
backgroundColor: errorColor,
contentTextStyle: _getBodyStyle(14).copyWith(color: Colors.white),
),
);
}
// Méthodes privées pour la typographie
TextStyle _getTitleStyle(double fontSize) {
return GoogleFonts.merienda(
fontSize: fontSize,
fontWeight: FontWeight.w600,
color: textColor,
);
}
TextStyle _getBodyStyle(double fontSize) {
return GoogleFonts.merriweather(
fontSize: fontSize,
fontWeight: FontWeight.w300,
color: textColor,
);
}
}