import 'dart:developer'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'theme_state.dart'; import 'package:kmobile/config/theme_type.dart'; import 'package:shared_preferences/shared_preferences.dart'; class ThemeCubit extends Cubit { ThemeCubit(): super(ThemeViolet()) { loadTheme(); } Future loadTheme() async { final prefs = await SharedPreferences.getInstance(); final themeIndex = prefs.getInt('theme_type') ?? 0; // final isDark = prefs.getBool('is_dark_mode') ?? false; final type = ThemeType.values[themeIndex]; switch(type) { case ThemeType.blue: emit(ThemeBlue()); case ThemeType.violet: emit(ThemeViolet()); default: emit(ThemeViolet()); } } Future changeTheme(ThemeType type) async { final prefs = await SharedPreferences.getInstance(); await prefs.setInt('theme_type', type.index); log("Mode Change"); print("mode changed"); switch(type) { case ThemeType.blue: emit(ThemeBlue()); print('blue matched'); break; case ThemeType.violet: emit(ThemeViolet()); print('violet matched'); break; default: emit(ThemeBlue()); print('default macthed'); } } }