import 'package:flutter/material.dart'; import 'package:mobx/mobx.dart'; import '../utils/shared_pref.dart'; part 'app_store.g.dart'; AppStore appStore = AppStore(); class AppStore = AppStoreBase with _$AppStore; const String themeModePref = 'themeModePref'; const String colorSchemeIndexPref = 'colorSchemeIndexPref'; const String isSoundOnPref = 'isSoundOnPref'; const String isVibrationOnPref = 'isVibrationOnPref'; const String languagePref = 'languagePref'; abstract class AppStoreBase with Store { @observable ThemeMode themeMode = ThemeMode.system; @observable int colorSchemeIndex = 4; @observable bool isSoundOn = true; @observable bool isVibrationOn = true; @observable String selectedLanguage = 'en_US'; @action Future setThemeMode(ThemeMode value) async { themeMode = value; setPrefValue(themeModePref, themeMode.toString()); } @action Future setColorSchemeIndex(int value) async { colorSchemeIndex = value; await setPrefValue(colorSchemeIndexPref, colorSchemeIndex); } @action Future toggleSoundMode({bool? value}) async { isSoundOn = value ?? !isSoundOn; setPrefValue(isSoundOnPref, isSoundOn); } @action Future toggleVibrationMode({bool? value}) async { isVibrationOn = value ?? !isVibrationOn; setPrefValue(isVibrationOnPref, isVibrationOn); } @action Future setLanguage(String aLanguage) async { selectedLanguage = aLanguage; await setPrefValue(languagePref, aLanguage); } }