thl 6 년 전
부모
커밋
f5c03ec37a
3개의 변경된 파일22개의 추가작업 그리고 21개의 파일을 삭제
  1. 1 1
      README.md
  2. 19 18
      lib/src/sp_util.dart
  3. 2 2
      pubspec.yaml

+ 1 - 1
README.md

@@ -12,7 +12,7 @@
 ### 使用方式:
 ```yaml
 dependencies:
-  flustars: 0.2.0
+  flustars: 0.2.1
 ```
 
 ### [Flutter工具类库 flustars][flustars_github]   

+ 19 - 18
lib/src/sp_util.dart

@@ -39,9 +39,9 @@ class SpUtil {
     _prefs = await SharedPreferences.getInstance();
   }
 
-  static String getString(String key) {
-    if (_prefs == null) return null;
-    return _prefs.getString(key);
+  static String getString(String key, {String defValue: ''}) {
+    if (_prefs == null) return defValue;
+    return _prefs.getString(key) ?? defValue;
   }
 
   static Future<bool> putString(String key, String value) {
@@ -49,9 +49,9 @@ class SpUtil {
     return _prefs.setString(key, value);
   }
 
-  static bool getBool(String key) {
-    if (_prefs == null) return null;
-    return _prefs.getBool(key);
+  static bool getBool(String key, {bool defValue: false}) {
+    if (_prefs == null) return defValue;
+    return _prefs.getBool(key) ?? defValue;
   }
 
   static Future<bool> putBool(String key, bool value) {
@@ -59,9 +59,9 @@ class SpUtil {
     return _prefs.setBool(key, value);
   }
 
-  static int getInt(String key) {
-    if (_prefs == null) return null;
-    return _prefs.getInt(key);
+  static int getInt(String key, {int defValue: 0}) {
+    if (_prefs == null) return defValue;
+    return _prefs.getInt(key) ?? defValue;
   }
 
   static Future<bool> putInt(String key, int value) {
@@ -69,9 +69,9 @@ class SpUtil {
     return _prefs.setInt(key, value);
   }
 
-  static double getDouble(String key) {
-    if (_prefs == null) return null;
-    return _prefs.getDouble(key);
+  static double getDouble(String key, {double defValue: 0.0}) {
+    if (_prefs == null) return defValue;
+    return _prefs.getDouble(key) ?? defValue;
   }
 
   static Future<bool> putDouble(String key, double value) {
@@ -79,9 +79,10 @@ class SpUtil {
     return _prefs.setDouble(key, value);
   }
 
-  static List<String> getStringList(String key) {
-    if (_prefs == null) return null;
-    return _prefs.getStringList(key);
+  static List<String> getStringList(String key,
+      {List<String> defValue: const []}) {
+    if (_prefs == null) return defValue;
+    return _prefs.getStringList(key) ?? defValue;
   }
 
   static Future<bool> putStringList(String key, List<String> value) {
@@ -89,9 +90,9 @@ class SpUtil {
     return _prefs.setStringList(key, value);
   }
 
-  static dynamic getDynamic(String key) {
-    if (_prefs == null) return null;
-    return _prefs.get(key);
+  static dynamic getDynamic(String key, {Object defValue: null}) {
+    if (_prefs == null) return defValue;
+    return _prefs.get(key) ?? defValue;
   }
 
   static Set<String> getKeys() {

+ 2 - 2
pubspec.yaml

@@ -1,6 +1,6 @@
 name: flustars
 description: Flutter common utils library. ScreenUtil, SpUtil, WidgetUtil.
-version: 0.2.0
+version: 0.2.1
 author: thl <863764940@qq.com>
 homepage: https://github.com/Sky24n/flustars
 
@@ -14,7 +14,7 @@ dependencies:
   # https://github.com/tekartik/synchronized.dart
   synchronized: ^1.5.3
   # https://github.com/flutter/plugins/tree/master/packages/shared_preferences
-  shared_preferences: ^0.4.3
+  shared_preferences: ^0.5.0
 
 
 # For information on the generic Dart part of this file, see the