import 'package:hive_flutter/hive_flutter.dart'; import 'package:immich_mobile/constants/hive_box.dart'; enum AppSettingsEnum { threeStageLoading("threeStageLoading", false), themeMode("themeMode", "system"), // "light","dark","system" tilesPerRow("tilesPerRow", 4), storageIndicator("storageIndicator", true); const AppSettingsEnum(this.hiveKey, this.defaultValue); final String hiveKey; final T defaultValue; } class AppSettingsService { late final Box hiveBox; AppSettingsService() { hiveBox = Hive.box(userSettingInfoBox); } T getSetting(AppSettingsEnum settingType) { if (!hiveBox.containsKey(settingType.hiveKey)) { return _setDefault(settingType); } var result = hiveBox.get(settingType.hiveKey); if (result is! T) { return _setDefault(settingType); } return result; } setSetting(AppSettingsEnum settingType, T value) { hiveBox.put(settingType.hiveKey, value); } T _setDefault(AppSettingsEnum settingType) { hiveBox.put(settingType.hiveKey, settingType.defaultValue); return settingType.defaultValue; } }