import 'package:flutter/material.dart'; import 'package:flutter_project/shared/data/local/storage_service.dart'; import 'package:flutter_project/shared/domain/providers/sharedpreferences_storage_service_provider.dart'; import 'package:flutter_project/shared/globals.dart'; import 'package:flutter_project/shared/theme/app_colors.dart'; import 'package:flutter_project/shared/theme/test_styles.dart'; import 'package:flutter_project/shared/theme/text_theme.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; final appThemeProvider = StateNotifierProvider( (ref) { final storage = ref.watch(storageServiceProvider); return AppThemeModeNotifier(storage); }, ); class AppThemeModeNotifier extends StateNotifier { final StroageService stroageService; ThemeMode currentTheme = ThemeMode.light; AppThemeModeNotifier(this.stroageService) : super(ThemeMode.light) { getCurrentTheme(); } void toggleTheme() { state = state == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark; stroageService.set(APP_THEME_STORAGE_KEY, state.name); } void getCurrentTheme() async { final theme = await stroageService.get(APP_THEME_STORAGE_KEY); final value = ThemeMode.values.byName('${theme ?? 'light'}'); state = value; } } class AppTheme { static ThemeData get darkTheme { return ThemeData( brightness: Brightness.dark, fontFamily: AppTextStyles.fontFamily, primaryColor: AppColors.primary, colorScheme: const ColorScheme.dark( primary: AppColors.primary, secondary: AppColors.lightGrey, error: AppColors.error, background: AppColors.black, ), backgroundColor: AppColors.black, scaffoldBackgroundColor: AppColors.black, textTheme: TextThemes.darkTextTheme, primaryTextTheme: TextThemes.primaryTextTheme, appBarTheme: const AppBarTheme( elevation: 0, backgroundColor: AppColors.black, titleTextStyle: AppTextStyles.h2, ), ); } /// Light theme data of the app static ThemeData get lightTheme { return ThemeData( brightness: Brightness.light, primaryColor: AppColors.primary, textTheme: TextThemes.textTheme, primaryTextTheme: TextThemes.primaryTextTheme, colorScheme: const ColorScheme.light( primary: AppColors.primary, secondary: AppColors.lightGrey, error: AppColors.error, ), appBarTheme: const AppBarTheme( elevation: 0, backgroundColor: AppColors.primary, ), ); } }