From fa705507ba574c857b1667553737d23b1b7ff495 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 12 五月 2022 12:06:31 +0800
Subject: [PATCH] 后端模板代码优化

---
 src/main/resources/code/flutter_module/lib/utils/setting_util.dart |   53 +++++++++++++++++++++++++++--------------------------
 1 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/src/main/resources/code/flutter_module/lib/utils/setting_util.dart b/src/main/resources/code/flutter_module/lib/utils/setting_util.dart
index cf0b872..cca866c 100644
--- a/src/main/resources/code/flutter_module/lib/utils/setting_util.dart
+++ b/src/main/resources/code/flutter_module/lib/utils/setting_util.dart
@@ -1,46 +1,47 @@
 
-import 'package:shared_preferences/shared_preferences.dart';
+
+import 'share_preference.dart';
 
 class SettingUtil {
   //璁剧疆鎺ㄩ��
   static Future<bool> setPush(bool enable) async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    return await prefs.setBool("setting_push", enable);
+    await _setSetting("pushUnDisturb", enable);
+    return true;
   }
 
   ///鏄惁鍏佽鎺ㄩ��
-  static Future<bool> isEnablePush() async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    bool? result = prefs.getBool("setting_push");
-    result ??= true;
-    return result;
+  static Future<bool?> isEnablePush() async {
+    return await _getSetting("pushUnDisturb");
   }
 
   //璁剧疆鎺ㄨ崘骞垮憡
   static Future<bool> setRecommendAd(bool enable) async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    return await prefs.setBool("setting_recommend_ad", enable);
+    await _setSetting("adRecommend", enable);
+    return true;
   }
 
   ///鏄惁鍏佽鎺ㄨ崘骞垮憡
-  static Future<bool> isEnableRecommendAd() async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    bool? result = prefs.getBool("setting_recommend_ad");
-    result ??= true;
-    return result;
+  static Future<bool?> isEnableRecommendAd() async {
+    return await _getSetting("adRecommend");
   }
 
-  //璁剧疆鎺ㄨ崘骞垮憡
-  static Future<bool> setLocationSpan(int second) async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    return await prefs.setInt("setting_location_span", second);
+  //璁剧疆鎺ㄨ崘鍐呭
+  static Future<bool> setRecommendContent(bool enable) async {
+    await _setSetting("contentRecommend", enable);
+    return true;
   }
 
-  ///鏄惁鍏佽鎺ㄨ崘骞垮憡
-  static Future<int> getLocationSpan() async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    int? result = prefs.getInt("setting_location_span");
-    result ??= 30;
-    return result;
+  ///鏄惁鍏佽鎺ㄨ崘鍐呭
+  static Future<bool?> isEnableRecommendContent() async {
+    return await _getSetting("contentRecommend");
   }
-}
+
+  static _setSetting(String key, bool value) async {
+    await dataMethodChannel
+        .invokeMethod("setSetting", {"key": key, "value": value});
+  }
+
+  static Future<bool?> _getSetting(String key) async {
+    return await dataMethodChannel.invokeMethod("getSetting", key);
+  }
+}
\ No newline at end of file

--
Gitblit v1.8.0