tanghongliang 7 năm trước cách đây
mục cha
commit
6a50b6b683
4 tập tin đã thay đổi với 36 bổ sung19 xóa
  1. 4 0
      CHANGELOG.md
  2. 1 1
      README.md
  3. 29 16
      lib/src/sp_util.dart
  4. 2 2
      pubspec.yaml

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 ## 0.1.0
 ## 0.1.0
 
 
+* TODO: SpUtil updated.
+
+## 0.1.0
+
 * TODO: Contains SpUtil,ScreenUtil,WidgetUtil.
 * TODO: Contains SpUtil,ScreenUtil,WidgetUtil.
 
 
 ## 0.0.1
 ## 0.0.1

+ 1 - 1
README.md

@@ -18,7 +18,7 @@
  8、ObjectUtil  : 判断对象是否为空(String List Map),判断两个List是否相等. 
  8、ObjectUtil  : 判断对象是否为空(String List Map),判断两个List是否相等. 
 
 
 ## Demo: [flutter_demos](https://github.com/Sky24n/flutter_demos).
 ## Demo: [flutter_demos](https://github.com/Sky24n/flutter_demos).
-## APK: [点击下载v1.0.2](https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppStore/flutter_demos.apk)
+## APK: [点击下载v1.0.4](https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppStore/flutter_demos.apk)
 ## Android扫码下载APK
 ## Android扫码下载APK
   ![](https://github.com/Sky24n/LDocuments/blob/master/AppImgs/flutter_demos/qrcode.png)
   ![](https://github.com/Sky24n/LDocuments/blob/master/AppImgs/flutter_demos/qrcode.png)
 
 

+ 29 - 16
lib/src/sp_util.dart

@@ -13,7 +13,7 @@ import 'package:synchronized/synchronized.dart';
 ///
 ///
 class SpUtil {
 class SpUtil {
   static SpUtil _singleton;
   static SpUtil _singleton;
-  static SharedPreferences _sharedPreferences;
+  static SharedPreferences _SP;
   static Lock _lock = Lock();
   static Lock _lock = Lock();
 
 
   static Future<SpUtil> getInstance() async {
   static Future<SpUtil> getInstance() async {
@@ -27,62 +27,75 @@ class SpUtil {
   }
   }
 
 
   static void init() async {
   static void init() async {
-    _sharedPreferences = await SharedPreferences.getInstance();
+    _SP = await SharedPreferences.getInstance();
   }
   }
 
 
   static String getString(String key) {
   static String getString(String key) {
-    return _sharedPreferences.getString(key);
+    if (_SP == null) return null;
+    return _SP.getString(key);
   }
   }
 
 
   static Future<bool> putString(String key, String value) {
   static Future<bool> putString(String key, String value) {
-    return _sharedPreferences.setString(key, value);
+    if (_SP == null) return null;
+    return _SP.setString(key, value);
   }
   }
 
 
   static bool getBool(String key) {
   static bool getBool(String key) {
-    return _sharedPreferences.getBool(key);
+    if (_SP == null) return null;
+    return _SP.getBool(key);
   }
   }
 
 
   static Future<bool> putBool(String key, bool value) {
   static Future<bool> putBool(String key, bool value) {
-    return _sharedPreferences.setBool(key, value);
+    if (_SP == null) return null;
+    return _SP.setBool(key, value);
   }
   }
 
 
   static int getInt(String key) {
   static int getInt(String key) {
-    return _sharedPreferences.getInt(key);
+    if (_SP == null) return null;
+    return _SP.getInt(key);
   }
   }
 
 
   static Future<bool> putInt(String key, int value) {
   static Future<bool> putInt(String key, int value) {
-    return _sharedPreferences.setInt(key, value);
+    if (_SP == null) return null;
+    return _SP.setInt(key, value);
   }
   }
 
 
   static double getDouble(String key) {
   static double getDouble(String key) {
-    return _sharedPreferences.getDouble(key);
+    if (_SP == null) return null;
+    return _SP.getDouble(key);
   }
   }
 
 
   static Future<bool> putDouble(String key, double value) {
   static Future<bool> putDouble(String key, double value) {
-    return _sharedPreferences.setDouble(key, value);
+    if (_SP == null) return null;
+    return _SP.setDouble(key, value);
   }
   }
 
 
   static List<String> getStringList(String key) {
   static List<String> getStringList(String key) {
-    return _sharedPreferences.getStringList(key);
+    return _SP.getStringList(key);
   }
   }
 
 
   static Future<bool> putStringList(String key, List<String> value) {
   static Future<bool> putStringList(String key, List<String> value) {
-    return _sharedPreferences.setStringList(key, value);
+    if (_SP == null) return null;
+    return _SP.setStringList(key, value);
   }
   }
 
 
   static dynamic getDynamic(String key) {
   static dynamic getDynamic(String key) {
-    return _sharedPreferences.get(key);
+    if (_SP == null) return null;
+    return _SP.get(key);
   }
   }
 
 
   static Set<String> getKeys() {
   static Set<String> getKeys() {
-    return _sharedPreferences.getKeys();
+    if (_SP == null) return null;
+    return _SP.getKeys();
   }
   }
 
 
   static Future<bool> remove(String key) {
   static Future<bool> remove(String key) {
-    return _sharedPreferences.remove(key);
+    if (_SP == null) return null;
+    return _SP.remove(key);
   }
   }
 
 
   static Future<bool> clear() {
   static Future<bool> clear() {
-    return _sharedPreferences.clear();
+    if (_SP == null) return null;
+    return _SP.clear();
   }
   }
 }
 }

+ 2 - 2
pubspec.yaml

@@ -1,6 +1,6 @@
 name: flustars
 name: flustars
 description: Flutter common utils library. SpUtil, ScreenUtil, WidgetUtil.
 description: Flutter common utils library. SpUtil, ScreenUtil, WidgetUtil.
-version: 0.1.0
+version: 0.1.1
 author: thl <863764940@qq.com>
 author: thl <863764940@qq.com>
 homepage: https://github.com/Sky24n/flustars
 homepage: https://github.com/Sky24n/flustars
 
 
@@ -12,7 +12,7 @@ dependencies:
     sdk: flutter
     sdk: flutter
 
 
   synchronized: ^1.5.3
   synchronized: ^1.5.3
-  shared_preferences: ^0.4.2
+  shared_preferences: ^0.4.3
 
 
 
 
 # For information on the generic Dart part of this file, see the
 # For information on the generic Dart part of this file, see the