import 'package:wonders/common_libs.dart'; import 'package:wonders/logic/common/platform_info.dart'; import 'package:wonders/logic/common/save_load_mixin.dart'; class SettingsLogic with ThrottledSaveLoadMixin { @override String get fileName => 'settings.dat'; late final hasCompletedOnboarding = ValueNotifier(false)..addListener(scheduleSave); late final hasDismissedSearchMessage = ValueNotifier(false)..addListener(scheduleSave); late final isSearchPanelOpen = ValueNotifier(true)..addListener(scheduleSave); late final currentLocale = ValueNotifier(null)..addListener(scheduleSave); late final prevWonderIndex = ValueNotifier(null)..addListener(scheduleSave); final bool useBlurs = !PlatformInfo.isAndroid; Future changeLocale(Locale value) async { currentLocale.value = value.languageCode; await localeLogic.loadIfChanged(value); // Re-init controllers that have some cached data that is localized wondersLogic.init(); timelineLogic.init(); } @override void copyFromJson(Map value) { hasCompletedOnboarding.value = value['hasCompletedOnboarding'] ?? false; hasDismissedSearchMessage.value = value['hasDismissedSearchMessage'] ?? false; currentLocale.value = value['currentLocale']; isSearchPanelOpen.value = value['isSearchPanelOpen'] ?? false; prevWonderIndex.value = value['lastWonderIndex']; } @override Map toJson() { return { 'hasCompletedOnboarding': hasCompletedOnboarding.value, 'hasDismissedSearchMessage': hasDismissedSearchMessage.value, 'currentLocale': currentLocale.value, 'isSearchPanelOpen': isSearchPanelOpen.value, 'lastWonderIndex': prevWonderIndex.value, }; } }