thl 6 роки тому
батько
коміт
e28b58abf2
6 змінених файлів з 166 додано та 213 видалено
  1. 19 185
      README.md
  2. 113 0
      docs/UPDATELOG.md
  3. BIN
      example/assets/images/ali_connors.png
  4. 30 27
      example/lib/main.dart
  5. 3 0
      example/pubspec.yaml
  6. 1 1
      lib/src/screen_util.dart

+ 19 - 185
README.md

@@ -2,135 +2,19 @@
 [![Pub](https://img.shields.io/pub/v/flustars.svg?style=flat-square)](https://pub.dartlang.org/packages/flustars)
 
 ## [flustars] Flutter常用工具类库。主要对第三方库封装,以便于使用。如果你有好的工具类欢迎PR. 
+
+## [更新说明](../docs/UPDATELOG.md)
  
 ### 关于使用本开源库
 如果您是用于公司项目,请随意使用~  
 如果您是用于开源项目,未经本人许可,请勿copy源码到您的项目使用!  
-使用方式:
+
+### 使用方式:
 ```yaml
 dependencies:
   flustars: 0.1.9
 ```
 
-## 更新说明
-#### v0.1.9(2019.01.07)   
-移除DioUtil,如有需要,请到[flutter_wanandroid][flutter_wanandroid_github]该项目中copy。
-
-#### v0.1.8(2018.12.29)   
-ScreenUtil 屏幕适配更新。  
-方案一、不依赖context
-```
-步骤 1
-//如果设计稿尺寸默认配置一致,无需该设置。  配置设计稿尺寸 默认 360.0 / 640.0 / 3.0
-setDesignWHD(_designW,_designH,_designD);  
-  
-步骤 2
-// 在MainPageState build 调用MediaQuery.of(context)
-class MainPageState extends State<MainPage> {
-  @override
-  Widget build(BuildContext context) {
-  
-    // 在 MainPageState build 调用 MediaQuery.of(context)
-    MediaQuery.of(context);
-    
-    double width = ScreenUtil.getInstance().screenWidth;
-    double height = ScreenUtil.getInstance().screenHeight;
-    return new Scaffold(
-      appBar: new AppBar(),
-    );
-  }
-}  
-  
-步骤 3
-ScreenUtil.getInstance().screenWidth
-ScreenUtil.getInstance().screenHeight
-ScreenUtil.getInstance().screenDensity
-ScreenUtil.getInstance().statusBarHeight
-ScreenUtil.getInstance().bottomBarHeight
-//屏幕适配相关  
-ScreenUtil.getInstance().getWidth(size); //返回根据屏幕宽适配后尺寸(单位 dp or pt)
-ScreenUtil.getInstance().getHeight(size); //返回根据屏幕高适配后尺寸 (单位 dp or pt)
-ScreenUtil.getInstance().getWidthPx(sizePx); //sizePx 单位px
-ScreenUtil.getInstance().getHeightPx(sizePx); //sizePx 单位px
-ScreenUtil.getInstance().getSp(fontSize); //返回根据屏幕宽适配后字体尺寸
-
-```
-方案二、依赖context
-```
-//如果设计稿尺寸默认配置一致,无需该设置。  配置设计稿尺寸 默认 360.0 / 640.0 / 3.0
-setDesignWHD(_designW,_designH,_designD);  
-
-ScreenUtil.getScreenW(context); //屏幕 宽
-ScreenUtil.getScreenH(context); //屏幕 高
-ScreenUtil.getScreenDensity(context); //屏幕 像素密度
-ScreenUtil.getStatusBarH(context); //状态栏高度
-ScreenUtil.getBottomBarH(context); //bottombar 高度
-//屏幕适配相关  
-ScreenUtil.getScaleW(context, size); //返回根据屏幕宽适配后尺寸(单位 dp or pt)
-ScreenUtil.getScaleH(context, size); //返回根据屏幕高适配后尺寸 (单位 dp or pt)
-ScreenUtil.getScaleSp(context, size) ;//返回根据屏幕宽适配后字体尺寸
-```
-
-#### v0.1.6(2018.12.20)  
-新增网络请求工具DioUtil, 单例模式,可输出请求日志。详细请求+解析请参考[flutter_wanandroid][flutter_wanandroid_github]项目。
-```
-// 打开debug模式.
-DioUtil.openDebug(); 
-
-// 配置网络参数.
-Options options = DioUtil.getDefOptions();
-options.baseUrl = "http://www.wanandroid.com/";
-HttpConfig config = new HttpConfig(options: options);
-DioUtil().setConfig(config);
-  
-// 两种单例请求方式.
-DioUtil().request<List>(Method.get, "banner/json");
-DioUtil.getInstance().request(Method.get, "banner/json");
-  
-//示例
-LoginReq req = new LoginReq('username', 'password');
-DioUtil().request(Method.post, "user/login",data: req.toJson());
-  
-//示例
-FormData formData = new FormData.from({
-      "username": "username",
-      "password": "password",
-    });
-DioUtil().requestR(Method.post, "user/login",data: rformData);
-  
-// 网络请求日志  
-I/flutter ( 5922): ----------------Http Log----------------
-I/flutter ( 5922): [statusCode]:   200
-I/flutter ( 5922): [request   ]:   method: GET  baseUrl: http://www.wanandroid.com/  path: lg/collect/list/0/json
-I/flutter ( 5922): [reqdata   ]:   null
-I/flutter ( 5922): [response  ]:   {data: {curPage: 1, datas: [], offset: 0, over: true, pageCount: 0, size: 20, total: 0}, errorCode: 0, errorMsg: }
-```
-
-#### v0.1.5(2018.12.14)  
-ScreenUtil 新增屏幕适配。
-```
-//如果设计稿尺寸默认配置一致,无需该设置。  配置设计稿尺寸 默认 360.0 / 640.0 / 3.0
-setDesignWHD(_designW,_designH,_designD);
-
-//返回根据屏幕宽适配后尺寸(单位 dp or pt)
-ScreenUtil.getInstance().getWidth(100.0);  
-
-//返回根据屏幕高适配后尺寸(单位 dp or pt)
-ScreenUtil.getInstance().getHeight(100.0); 
-
-//返回根据屏幕宽适配后字体尺寸
-ScreenUtil.getInstance().getSp(12.0); 
-```
-v0.1.4(2018.11.22)  
-ScreenUtil不依赖context获取屏幕数据。  
-
-新增MyAppBar,不需要GlobalKey就能openDrawer。  
-
-## 关于示例
-本项目中不包含示例,所有示例均在[flutter_demos][flutter_demos_github]项目中。  
-
-完整项目[flutter_wanandroid][flutter_wanandroid_github],包含启动页,引导页,主题色切换,应用国际化多语言,版本更新等功能。欢迎体验!  
-
 ### [Flutter工具类库 flustars][flustars_github]   
  1、SpUtil       : 单例"同步" SharedPreferences 工具类.  
  2、ScreenUtil   : 屏幕适配,获取屏幕宽、高、密度,AppBar高,状态栏高度,屏幕方向.  
@@ -146,25 +30,8 @@ ScreenUtil不依赖context获取屏幕数据。
  7、NumUtil      : 保留x位小数, 精确加、减、乘、除, 防止精度丢失.  
  8、ObjectUtil   : 判断对象是否为空(String List Map),判断两个List是否相等. 
 
-## Demo Github :  
- [flutter_wanandroid][flutter_wanandroid_github] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [flutter_demos][flutter_demos_github]
-## 点击下载APK :  
- [v0.1.2][flutter_wanandroid_apk] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [v1.0.4][flutter_demos_apk]
-## 扫码下载APK :
-  ![flutter_wanandroid][flutter_wanandroid_qr] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ![flutter_demos][flutter_demos_qr]
-
-### Screenshot
-<img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20181003-234414.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20181003-211011.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180930-012302.jpg" width="200">  
-<img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180930-012431.jpg" width="200">  <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-231618.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180926-144840.png" width="200">  
-<img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-224204.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-224146.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-224231.jpg" width="200">   
-
 ### APIs
-
-```yaml
-dependencies:
-  flustars: x.x.x  #latest version
-```
-* #### SpUtil
+* #### SpUtil -> [Example]()
 ```
 getString
 putString
@@ -183,7 +50,7 @@ clear
 isInitialized
 ```
 
-* #### ScreenUtil
+* #### ScreenUtil -> [Example]() 
 ```
 getWidth                  : 返回根据屏幕宽适配后尺寸.
 getHeight                 : 返回根据屏幕高适配后尺寸.
@@ -204,63 +71,30 @@ getScaleH(ctx,size)       : 返回根据屏幕高适配后尺寸.
 getScaleSp(ctx,size)      : 返回根据屏幕宽适配后字体尺寸.
 ```
 
-* #### WidgetUtil
+* #### WidgetUtil -> [Example]()
 ```
 asyncPrepare              : Widget渲染监听,监听widget宽高变化,callback返回宽高等参数.
 getWidgetBounds           : 获取widget 宽高.
 getWidgetLocalToGlobal    : 获取widget在屏幕上的坐标.
 ```
 
-
-### Example
-
-``` dart
-// Import package
-import 'package:flustars/flustars.dart';
-
-//SpUtil
-SpUtil spUtil = await SpUtil.getInstance();
-//SpUtil.remove("username");
-SpUtil.putString("username", "sky224");
-LogUtil.e("username: " + SpUtil.getString("username").toString());
-
-//ScreenUtil
-ScreenUtil.getInstance().init(context);
-
-ScreenUtil.screenWidth
-ScreenUtil.screenHeight
-ScreenUtil.statusBarHeight
-ScreenUtil.screenDensity
-
-//WidgetUtil
-WidgetUtil widgetUtil = new WidgetUtil();
-
-@override
-Widget build(BuildContext context) {
-  widgetUtil.asyncPrepare(context, false, (Rect rect) {
-     double width = rect.width;
-     double height = rect.height;
-  });
-    return ;
- }
-
-//Widgets must be rendered completely. Otherwise return Rect.zero.
-Rect rect = WidgetUtil.getWidgetBounds(context);
-double width = rect.width;
-double height = rect.height;
-
-//Widgets must be rendered completely. Otherwise return Offset.zero.
-Offset offset = WidgetUtil.getWidgetLocalToGlobal(context);
-double dx = offset.dx  
-double dx = offset.dy
-
-```
-
 ## 关于作者,欢迎关注~
  [![jianshu][jianshuSvg]][jianshu]   [![juejin][juejinSvg]][juejin] 
  
 ### 最后,如果您觉得本项目不错的话,来个star支持下作者吧! 
 
+## Demo Github :  
+ [flutter_wanandroid][flutter_wanandroid_github] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [flutter_demos][flutter_demos_github]
+## 点击下载APK :  
+ [v0.1.2][flutter_wanandroid_apk] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [v1.0.4][flutter_demos_apk]
+## 扫码下载APK :
+  ![flutter_wanandroid][flutter_wanandroid_qr] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ![flutter_demos][flutter_demos_qr]
+
+### Screenshot
+<img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20181003-234414.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20181003-211011.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180930-012302.jpg" width="200">  
+<img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180930-012431.jpg" width="200">  <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-231618.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180926-144840.png" width="200">  
+<img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-224204.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-224146.jpg" width="200">   <img src="https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_demos/Screenshot_20180919-224231.jpg" width="200">   
+
 [flutter_wanandroid_github]: https://github.com/Sky24n/flutter_wanandroid
 [flutter_wanandroid_apk]: https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppStore/flutter_wanandroid.apk
 [flutter_wanandroid_qr]: https://raw.githubusercontent.com/Sky24n/LDocuments/master/AppImgs/flutter_wanandroid/qrcode.png

+ 113 - 0
docs/UPDATELOG.md

@@ -0,0 +1,113 @@
+## 更新说明
+#### v0.1.9(2019.01.07)   
+移除DioUtil,如有需要,请到[flutter_wanandroid][flutter_wanandroid_github]该项目中copy。
+
+#### v0.1.8(2018.12.29)   
+ScreenUtil 屏幕适配更新。  
+方案一、不依赖context
+```
+步骤 1
+//如果设计稿尺寸默认配置一致,无需该设置。  配置设计稿尺寸 默认 360.0 / 640.0 / 3.0
+setDesignWHD(_designW,_designH,_designD);  
+  
+步骤 2
+// 在MainPageState build 调用MediaQuery.of(context)
+class MainPageState extends State<MainPage> {
+  @override
+  Widget build(BuildContext context) {
+  
+    // 在 MainPageState build 调用 MediaQuery.of(context)
+    MediaQuery.of(context);
+    
+    double width = ScreenUtil.getInstance().screenWidth;
+    double height = ScreenUtil.getInstance().screenHeight;
+    return new Scaffold(
+      appBar: new AppBar(),
+    );
+  }
+}  
+  
+步骤 3
+ScreenUtil.getInstance().screenWidth
+ScreenUtil.getInstance().screenHeight
+ScreenUtil.getInstance().screenDensity
+ScreenUtil.getInstance().statusBarHeight
+ScreenUtil.getInstance().bottomBarHeight
+//屏幕适配相关  
+ScreenUtil.getInstance().getWidth(size); //返回根据屏幕宽适配后尺寸(单位 dp or pt)
+ScreenUtil.getInstance().getHeight(size); //返回根据屏幕高适配后尺寸 (单位 dp or pt)
+ScreenUtil.getInstance().getWidthPx(sizePx); //sizePx 单位px
+ScreenUtil.getInstance().getHeightPx(sizePx); //sizePx 单位px
+ScreenUtil.getInstance().getSp(fontSize); //返回根据屏幕宽适配后字体尺寸
+
+```
+方案二、依赖context
+```
+//如果设计稿尺寸默认配置一致,无需该设置。  配置设计稿尺寸 默认 360.0 / 640.0 / 3.0
+setDesignWHD(_designW,_designH,_designD);  
+
+ScreenUtil.getScreenW(context); //屏幕 宽
+ScreenUtil.getScreenH(context); //屏幕 高
+ScreenUtil.getScreenDensity(context); //屏幕 像素密度
+ScreenUtil.getStatusBarH(context); //状态栏高度
+ScreenUtil.getBottomBarH(context); //bottombar 高度
+//屏幕适配相关  
+ScreenUtil.getScaleW(context, size); //返回根据屏幕宽适配后尺寸(单位 dp or pt)
+ScreenUtil.getScaleH(context, size); //返回根据屏幕高适配后尺寸 (单位 dp or pt)
+ScreenUtil.getScaleSp(context, size) ;//返回根据屏幕宽适配后字体尺寸
+```
+
+#### v0.1.6(2018.12.20)  
+新增网络请求工具DioUtil, 单例模式,可输出请求日志。详细请求+解析请参考[flutter_wanandroid][flutter_wanandroid_github]项目。
+```
+// 打开debug模式.
+DioUtil.openDebug(); 
+
+// 配置网络参数.
+Options options = DioUtil.getDefOptions();
+options.baseUrl = "http://www.wanandroid.com/";
+HttpConfig config = new HttpConfig(options: options);
+DioUtil().setConfig(config);
+  
+// 两种单例请求方式.
+DioUtil().request<List>(Method.get, "banner/json");
+DioUtil.getInstance().request(Method.get, "banner/json");
+  
+//示例
+LoginReq req = new LoginReq('username', 'password');
+DioUtil().request(Method.post, "user/login",data: req.toJson());
+  
+//示例
+FormData formData = new FormData.from({
+      "username": "username",
+      "password": "password",
+    });
+DioUtil().requestR(Method.post, "user/login",data: rformData);
+  
+// 网络请求日志  
+I/flutter ( 5922): ----------------Http Log----------------
+I/flutter ( 5922): [statusCode]:   200
+I/flutter ( 5922): [request   ]:   method: GET  baseUrl: http://www.wanandroid.com/  path: lg/collect/list/0/json
+I/flutter ( 5922): [reqdata   ]:   null
+I/flutter ( 5922): [response  ]:   {data: {curPage: 1, datas: [], offset: 0, over: true, pageCount: 0, size: 20, total: 0}, errorCode: 0, errorMsg: }
+```
+
+#### v0.1.5(2018.12.14)  
+ScreenUtil 新增屏幕适配。
+```
+//如果设计稿尺寸默认配置一致,无需该设置。  配置设计稿尺寸 默认 360.0 / 640.0 / 3.0
+setDesignWHD(_designW,_designH,_designD);
+
+//返回根据屏幕宽适配后尺寸(单位 dp or pt)
+ScreenUtil.getInstance().getWidth(100.0);  
+
+//返回根据屏幕高适配后尺寸(单位 dp or pt)
+ScreenUtil.getInstance().getHeight(100.0); 
+
+//返回根据屏幕宽适配后字体尺寸
+ScreenUtil.getInstance().getSp(12.0); 
+```
+v0.1.4(2018.11.22)  
+ScreenUtil不依赖context获取屏幕数据。  
+
+新增MyAppBar,不需要GlobalKey就能openDrawer。  

BIN
example/assets/images/ali_connors.png


+ 30 - 27
example/lib/main.dart

@@ -10,24 +10,26 @@ class MyApp extends StatefulWidget {
 }
 
 class _MyAppState extends State<MyApp> {
-  String _userName = '';
-
   @override
   void initState() {
     super.initState();
+
+    /// 配置设计稿尺寸
+    /// 如果设计稿尺寸默认配置一致,无需该设置。默认 width:360.0 / height:640.0 / density:3.0
+    setDesignWHD(360.0, 640, density: 3);
+
     _initAsync();
   }
 
   void _initAsync() async {
     print("SpUtil: " + SpUtil.isInitialized().toString());
-    SpUtil spUtil = await SpUtil.getInstance();
-    //SpUtil.remove("username");
+    await SpUtil.getInstance();
     print("SpUtil: " + SpUtil.isInitialized().toString());
     SpUtil.putString("username", "sky24");
     print("username: " + SpUtil.getString("username").toString());
     if (!mounted) return;
     setState(() {
-      _userName = SpUtil.getString("username");
+      String _userName = SpUtil.getString("username");
     });
   }
 
@@ -36,21 +38,6 @@ class _MyAppState extends State<MyApp> {
     return new MaterialApp(
       home: new MainPage(),
     );
-
-//    return new MaterialApp(
-//      home: new Scaffold(
-//        appBar: new AppBar(
-//          title: const Text('Plugin example app'),
-//        ),
-//        body: new Center(
-//          child: new Text('username: $_userName'),
-//        ),
-//        floatingActionButton: new FloatingActionButton(onPressed: () {
-//          Navigator.push(
-//              context, new CupertinoPageRoute(builder: (ctx) => TestPage()));
-//        }),
-//      ),
-//    );
   }
 }
 
@@ -62,21 +49,16 @@ class MainPage extends StatefulWidget {
 }
 
 class MainPageState extends State<MainPage> {
-  WidgetUtil widgetUtil = new WidgetUtil();
-
   @override
   void initState() {
     super.initState();
-    widgetUtil.asyncPrepares(true, (_) {
-      print("Widget 渲染完成...");
-    });
   }
 
   @override
   Widget build(BuildContext context) {
     // 如果使用ScreenUtil.getInstance()
     // 需要MainPageState build 调用MediaQuery.of(context)
-    MediaQuery.of(context);
+//    MediaQuery.of(context);
 
     double width = ScreenUtil.getInstance().screenWidth;
     double height = ScreenUtil.getInstance().screenHeight;
@@ -95,7 +77,20 @@ class MainPageState extends State<MainPage> {
         "_width: $_width, height: $_height, __tempW: $__tempW, tempW: $tempW, tempH: $tempH");
 
     return new Scaffold(
-      appBar: new AppBar(),
+      // 一个不需要GlobalKey就可以openDrawer的AppBar
+      appBar: new MyAppBar(
+        leading: ClipOval(
+          child: new Image.asset(('assets/images/ali_connors.png')),
+        ),
+        title: const Text('Flustars Demos'),
+        centerTitle: true,
+        actions: <Widget>[
+          new IconButton(
+            icon: new Icon(Icons.search),
+            onPressed: () {},
+          ),
+        ],
+      ),
       body: new Column(
         crossAxisAlignment: CrossAxisAlignment.start,
         children: <Widget>[
@@ -159,6 +154,14 @@ class MainPageState extends State<MainPage> {
           ),
         ],
       ),
+      drawer: new Container(
+        color: Colors.white,
+        width: ScreenUtil.getInstance().getWidth(100),
+        height: double.infinity,
+        child: new SizedBox(
+          width: ScreenUtil.getInstance().getWidth(100),
+        ),
+      ),
     );
   }
 }

+ 3 - 0
example/pubspec.yaml

@@ -37,6 +37,9 @@ flutter:
   # included with your application, so that you can use the icons in
   # the material Icons class.
   uses-material-design: true
+  assets:
+    - assets/images/ali_connors.png
+
 
   # To add assets to your application, add an assets section, like this:
   # assets:

+ 1 - 1
lib/src/screen_util.dart

@@ -97,7 +97,7 @@ class ScreenUtil {
   /// 当前屏幕 高
   static double getScreenH(BuildContext context) {
     MediaQueryData mediaQuery = MediaQuery.of(context);
-    return mediaQuery.size.width;
+    return mediaQuery.size.height;
   }
 
   /// screen density