2022-09-07 13:25:56 -06:00
|
|
|
import 'package:wonders/common_libs.dart';
|
2022-11-05 02:06:51 -06:00
|
|
|
import 'package:wonders/logic/common/platform_info.dart';
|
2022-08-29 20:38:28 -06:00
|
|
|
import 'package:wonders/logic/common/save_load_mixin.dart';
|
|
|
|
|
|
|
|
class SettingsLogic with ThrottledSaveLoadMixin {
|
|
|
|
@override
|
|
|
|
String get fileName => 'settings.dat';
|
|
|
|
|
|
|
|
late final hasCompletedOnboarding = ValueNotifier<bool>(false)..addListener(scheduleSave);
|
|
|
|
late final hasDismissedSearchMessage = ValueNotifier<bool>(false)..addListener(scheduleSave);
|
2022-09-08 12:14:28 -06:00
|
|
|
late final currentLocale = ValueNotifier<String?>(null)..addListener(scheduleSave);
|
2022-08-29 20:38:28 -06:00
|
|
|
|
2022-11-05 02:06:51 -06:00
|
|
|
final bool useBlurs = !PlatformInfo.isAndroid;
|
2022-08-29 20:38:28 -06:00
|
|
|
|
|
|
|
@override
|
|
|
|
void copyFromJson(Map<String, dynamic> value) {
|
|
|
|
hasCompletedOnboarding.value = value['hasCompletedOnboarding'] ?? false;
|
|
|
|
hasDismissedSearchMessage.value = value['hasDismissedSearchMessage'] ?? false;
|
2022-09-08 12:14:28 -06:00
|
|
|
currentLocale.value = value['currentLocale'];
|
2022-08-29 20:38:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return {
|
|
|
|
'hasCompletedOnboarding': hasCompletedOnboarding.value,
|
|
|
|
'hasDismissedSearchMessage': hasDismissedSearchMessage.value,
|
2022-09-08 12:14:28 -06:00
|
|
|
'currentLocale': currentLocale.value,
|
2022-08-29 20:38:28 -06:00
|
|
|
};
|
|
|
|
}
|
2022-09-07 13:25:56 -06:00
|
|
|
|
2022-09-08 12:14:28 -06:00
|
|
|
Future<void> changeLocale(Locale value) async {
|
2022-09-07 13:25:56 -06:00
|
|
|
currentLocale.value = value.languageCode;
|
2022-09-08 12:14:28 -06:00
|
|
|
await localeLogic.loadIfChanged(value);
|
|
|
|
// Re-init controllers that have some cached data that is localized
|
2022-09-07 13:25:56 -06:00
|
|
|
wondersLogic.init();
|
|
|
|
timelineLogic.init();
|
|
|
|
}
|
2022-08-29 20:38:28 -06:00
|
|
|
}
|