thl 6 anos atrás
pai
commit
bebf82bc90
6 arquivos alterados com 45 adições e 25 exclusões
  1. 7 1
      README.md
  2. 3 0
      docs/UPDATELOG.md
  3. 1 1
      example/lib/main.dart
  4. 32 22
      lib/src/screen_util.dart
  5. 1 0
      lib/src/sp_util.dart
  6. 1 1
      pubspec.yaml

+ 7 - 1
README.md

@@ -12,7 +12,7 @@
 ### 使用方式:
 ```yaml
 dependencies:
-  flustars: 0.1.9
+  flustars: 0.2.0
 ```
 
 ### [Flutter工具类库 flustars][flustars_github]   
@@ -30,6 +30,12 @@ dependencies:
  7、NumUtil      : 保留x位小数, 精确加、减、乘、除, 防止精度丢失.  
  8、ObjectUtil   : 判断对象是否为空(String List Map),判断两个List是否相等. 
 
+### Add dependency
+```yaml
+dependencies:
+  flustars: x.x.x  #latest version
+```
+
 ### APIs
 * #### SpUtil -> [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/ui/pages/demos/sp_util_page.dart)
 ```

+ 3 - 0
docs/UPDATELOG.md

@@ -111,3 +111,6 @@ v0.1.4(2018.11.22)
 ScreenUtil不依赖context获取屏幕数据。  
 
 新增MyAppBar,不需要GlobalKey就能openDrawer。  
+
+
+[flutter_wanandroid_github]: https://github.com/Sky24n/flutter_wanandroid

+ 1 - 1
example/lib/main.dart

@@ -18,7 +18,7 @@ class _MyAppState extends State<MyApp> {
     /// 如果设计稿尺寸默认配置一致,无需该设置。默认 width:360.0 / height:640.0 / density:3.0
     /// Configuration design draft size.
     /// If the default configuration of design draft size is the same, this setting is not required. default width:360.0 / height:640.0 / density:3.0
-    setDesignWHD(360.0, 640, density: 3);
+    setDesignWHD(360.0, 640.0, density: 3);
   }
 
   @override

+ 32 - 22
lib/src/screen_util.dart

@@ -35,7 +35,7 @@ class ScreenUtil {
   double _statusBarHeight = 0.0;
   double _bottomBarHeight = 0.0;
   double _appBarHeight = 0.0;
-  double _textScaleFactor = 0.0;
+  double _textScaleFactor = 1.0;
   MediaQueryData _mediaQueryData;
 
   static final ScreenUtil _singleton = ScreenUtil();
@@ -45,7 +45,6 @@ class ScreenUtil {
     return _singleton;
   }
 
-
   _init() {
     MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
     if (_mediaQueryData != mediaQuery) {
@@ -127,6 +126,7 @@ class ScreenUtil {
     return mediaQuery;
   }
 
+  /// returns the size after adaptation according to the screen width.(unit dp or pt)
   /// 返回根据屏幕宽适配后尺寸(单位 dp or pt)
   /// size 单位 dp or pt
   static double getScaleW(BuildContext context, double size) {
@@ -134,22 +134,25 @@ class ScreenUtil {
     return size * getScreenW(context) / _designW;
   }
 
+  /// returns the size after adaptation according to the screen height.(unit dp or pt)
   /// 返回根据屏幕高适配后尺寸 (单位 dp or pt)
-  /// size 单位 dp or pt
+  /// size unit dp or pt
   static double getScaleH(BuildContext context, double size) {
     if (context == null || getScreenH(context) == 0.0) return size;
     return size * getScreenH(context) / _designH;
   }
 
-  /// 返回根据屏幕宽适配后字体尺寸
+  /// returns the font size after adaptation according to the screen density.
+  /// 返回根据屏幕Density适配后字体尺寸
   /// fontSize 字体尺寸
-  /// sySystem 是否跟随系统字体大小设置,默认 true。
+  /// sySystem 是否跟随系统字体大小设置,默认 true。Whether to follow the system font size settings, default true.
   static double getScaleSp(BuildContext context, double fontSize,
       {bool sySystem: true}) {
-    if (context == null || getScreenW(context) == 0.0) return fontSize;
-    return (sySystem ? MediaQuery
-        .of(context)
-        .textScaleFactor : 1.0) * fontSize * getScreenW(context) / _designW;
+    if (context == null || getScreenDensity(context) == 0.0) return fontSize;
+    return (sySystem ? MediaQuery.of(context).textScaleFactor : 1.0) *
+        fontSize *
+        getScreenDensity(context) /
+        _designD;
   }
 
   /// Orientation
@@ -159,40 +162,47 @@ class ScreenUtil {
     return mediaQuery.orientation;
   }
 
+  /// returns the size after adaptation according to the screen width.(unit dp or pt)
   /// 返回根据屏幕宽适配后尺寸(单位 dp or pt)
   /// size 单位 dp or pt
   double getWidth(double size) {
     return _screenWidth == 0.0 ? size : (size * _screenWidth / _designW);
   }
 
-  /// 返回根据屏幕高适配后尺寸 (单位 dp or pt)
-  /// size 单位 dp or pt
+  /// returns the size after adaptation according to the screen height.(unit dp or pt)
+  /// 返回根据屏幕高适配后尺寸(单位 dp or pt)
+  /// size unit dp or pt
   double getHeight(double size) {
     return _screenHeight == 0.0 ? size : (size * _screenHeight / _designH);
   }
 
+  /// returns the size after adaptation according to the screen width.(unit dp or pt)
   /// 返回根据屏幕宽适配后尺寸(单位 dp or pt)
-  /// sizePx 单位px
+  /// sizePx unit px
   double getWidthPx(double sizePx) {
-    return _screenWidth == 0.0 ? (sizePx / _designD) :
-    (sizePx * _screenWidth / (_designW * _designD));
+    return _screenWidth == 0.0
+        ? (sizePx / _designD)
+        : (sizePx * _screenWidth / (_designW * _designD));
   }
 
+  /// returns the size after adaptation according to the screen height.(unit dp or pt)
   /// 返回根据屏幕高适配后尺寸(单位 dp or pt)
-  /// sizePx 单位px
+  /// sizePx unit px
   double getHeightPx(double sizePx) {
-    return _screenHeight == 0.0 ? (sizePx / _designD) :
-    (sizePx * _screenHeight / (_designH * _designD));
+    return _screenHeight == 0.0
+        ? (sizePx / _designD)
+        : (sizePx * _screenHeight / (_designH * _designD));
   }
 
-  /// 返回根据屏幕宽适配后字体尺寸
+  /// returns the font size after adaptation according to the screen density.
+  /// 返回根据屏幕Density适配后字体尺寸
   /// fontSize 字体尺寸
-  /// sySystem 是否跟随系统字体大小设置,默认 true。
+  /// sySystem 是否跟随系统字体大小设置,默认 true。Whether to follow the system font size settings, default true.
   double getSp(double fontSize, {bool sySystem: true}) {
-    if (_screenWidth == 0.0) return fontSize;
+    if (_screenDensity == 0.0) return fontSize;
     return (sySystem ? _textScaleFactor : 1.0) *
         fontSize *
-        _screenWidth /
-        _designW;
+        _screenDensity /
+        _designD;
   }
 }

+ 1 - 0
lib/src/sp_util.dart

@@ -80,6 +80,7 @@ class SpUtil {
   }
 
   static List<String> getStringList(String key) {
+    if (_prefs == null) return null;
     return _prefs.getStringList(key);
   }
 

+ 1 - 1
pubspec.yaml

@@ -1,6 +1,6 @@
 name: flustars
 description: Flutter common utils library. ScreenUtil, SpUtil, WidgetUtil.
-version: 0.1.9
+version: 0.2.0
 author: thl <863764940@qq.com>
 homepage: https://github.com/Sky24n/flustars