diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index ebeb85b9..c3c1ef1b 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -57,14 +57,12 @@ class GStorage { ); static List get tabbarSort => - List.from(setting.get(SettingBoxKey.tabbarSort, - defaultValue: HomeTabType.values.map((item) => item.name).toList())); + List.from(setting.get(SettingBoxKey.tabbarSort) ?? + HomeTabType.values.map((item) => item.name).toList()); static List> get blockSettings { - List list = List.from(setting.get( - SettingBoxKey.blockSettings, - defaultValue: List.generate(SegmentType.values.length, (_) => 1), - )); + List list = List.from(setting.get(SettingBoxKey.blockSettings) ?? + List.generate(SegmentType.values.length, (_) => 1)); return SegmentType.values .map((item) => Pair( first: item, @@ -74,10 +72,9 @@ class GStorage { } static List get blockColor { - List list = List.from(setting.get( - SettingBoxKey.blockColor, - defaultValue: List.generate(SegmentType.values.length, (_) => ''), - )); + List list = List.from( + setting.get(SettingBoxKey.blockColor) ?? + List.generate(SegmentType.values.length, (_) => '')); return SegmentType.values .map((item) => list[item.index].isNotEmpty ? Color( @@ -473,13 +470,17 @@ class GStorage { SettingBoxKey.pageTransition, defaultValue: Transition.native.index)]; - static num get maxCacheSize => GStorage.setting - .get(SettingBoxKey.maxCacheSize, defaultValue: pow(1024, 3)); + static num get maxCacheSize => + GStorage.setting.get(SettingBoxKey.maxCacheSize) ?? pow(1024, 3); static bool get optTabletNav => GStorage.setting.get(SettingBoxKey.optTabletNav, defaultValue: true); static bool get horizontalScreen { + return GStorage.setting.get(SettingBoxKey.horizontalScreen) ?? isTablet; + } + + static bool get isTablet { bool isTablet; if (Get.context != null) { isTablet = Get.context!.isTablet; @@ -489,15 +490,14 @@ class GStorage { final shortestSide = min(screenSize.width.abs(), screenSize.height.abs()); isTablet = shortestSide >= 600; } - return GStorage.setting - .get(SettingBoxKey.horizontalScreen, defaultValue: isTablet); + return isTablet; } static List get dynamicDetailRatio => List.from(setting .get(SettingBoxKey.dynamicDetailRatio, defaultValue: const [60.0, 40.0])); - static Set get blackMids => - GStorage.localCache.get(LocalCacheKey.blackMids, defaultValue: {}); + static Set get blackMids => GStorage.localCache + .get(LocalCacheKey.blackMids, defaultValue: const {}); static set blackMids(Set blackMidsSet) { GStorage.localCache.put(LocalCacheKey.blackMids, blackMidsSet); @@ -535,10 +535,8 @@ class GStorage { // ); // damping = ratio * 2.0 * math.sqrt(mass * stiffness) static final List springDescription = List.from( - setting.get( - SettingBoxKey.springDescription, // [mass, stiffness, damping] - defaultValue: [0.5, 100.0, 2.2 * sqrt(50)], - ), + setting.get(SettingBoxKey.springDescription) ?? + [0.5, 100.0, 2.2 * sqrt(50)], // [mass, stiffness, damping] ); // static Brightness get brightness {