thl 7 anos atrás
pai
commit
3689eed428

+ 4 - 0
CHANGELOG.md

@@ -1,3 +1,7 @@
+## 0.1.9
+
+* TODO: remove DioUtil.
+
 ## 0.1.8
 
 * TODO: fix ScreenUtil bug, Dio v1.0.13.

+ 6 - 16
README.md

@@ -4,6 +4,9 @@
 ## [flustars] Flutter常用工具类库。主要对第三方库封装,以便于使用。如果你有好的工具类欢迎PR.  
 
 ## 更新说明
+#### v0.1.9(2019.01.07)   
+移除DioUtil,如有需要,请到[flutter_wanandroid][flutter_wanandroid_github]该项目中copy。
+
 #### v0.1.8(2018.12.29)   
 ScreenUtil 屏幕适配更新。  
 方案一、不依赖context
@@ -120,10 +123,9 @@ ScreenUtil不依赖context获取屏幕数据。
 完整项目[flutter_wanandroid][flutter_wanandroid_github],包含启动页,引导页,主题色切换,应用国际化多语言,版本更新等功能。欢迎体验!  
 
 ### [Flutter工具类库 flustars][flustars_github]   
- 1、DioUtil      : Dio 工具类.   
- 2、SpUtil       : 单例"同步" SharedPreferences 工具类.  
- 3、ScreenUtil   : 屏幕适配,获取屏幕宽、高、密度,AppBar高,状态栏高度,屏幕方向.  
- 4、WidgetUtil   : 获取Widget宽高,在屏幕上的坐标.  
+ 1、SpUtil       : 单例"同步" SharedPreferences 工具类.  
+ 2、ScreenUtil   : 屏幕适配,获取屏幕宽、高、密度,AppBar高,状态栏高度,屏幕方向.  
+ 3、WidgetUtil   : 获取Widget宽高,在屏幕上的坐标.  
 
 ### [Dart常用工具类库 common_utils][common_utils_github]  
  1、TimelineUtil : 时间轴.(新)  
@@ -153,18 +155,6 @@ ScreenUtil不依赖context获取屏幕数据。
 dependencies:
   flustars: x.x.x  #latest version
 ```
-* #### DioUtil
-```
-openDebug()
-setConfig(config)
-request<T>(method, path, {data, options, cancelToken})
-requestR<T>(method, path, {data, options, cancelToken})
-download(urlPath,savePath, {...})
-getDio()
-getDefOptions()
-createNewDio()
-```
-
 * #### SpUtil
 ```
 getString

+ 1 - 0
example/ios/Flutter/Debug.xcconfig

@@ -1 +1,2 @@
+#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
 #include "Generated.xcconfig"

+ 1 - 0
example/ios/Flutter/Release.xcconfig

@@ -1 +1,2 @@
+#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
 #include "Generated.xcconfig"

+ 69 - 0
example/ios/Podfile

@@ -0,0 +1,69 @@
+# Uncomment this line to define a global platform for your project
+# platform :ios, '9.0'
+
+# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
+ENV['COCOAPODS_DISABLE_STATS'] = 'true'
+
+project 'Runner', {
+  'Debug' => :debug,
+  'Profile' => :release,
+  'Release' => :release,
+}
+
+def parse_KV_file(file, separator='=')
+  file_abs_path = File.expand_path(file)
+  if !File.exists? file_abs_path
+    return [];
+  end
+  pods_ary = []
+  skip_line_start_symbols = ["#", "/"]
+  File.foreach(file_abs_path) { |line|
+      next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
+      plugin = line.split(pattern=separator)
+      if plugin.length == 2
+        podname = plugin[0].strip()
+        path = plugin[1].strip()
+        podpath = File.expand_path("#{path}", file_abs_path)
+        pods_ary.push({:name => podname, :path => podpath});
+      else
+        puts "Invalid plugin specification: #{line}"
+      end
+  }
+  return pods_ary
+end
+
+target 'Runner' do
+  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
+  # referring to absolute paths on developers' machines.
+  system('rm -rf .symlinks')
+  system('mkdir -p .symlinks/plugins')
+
+  # Flutter Pods
+  generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
+  if generated_xcode_build_settings.empty?
+    puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
+  end
+  generated_xcode_build_settings.map { |p|
+    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
+      symlink = File.join('.symlinks', 'flutter')
+      File.symlink(File.dirname(p[:path]), symlink)
+      pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
+    end
+  }
+
+  # Plugin Pods
+  plugin_pods = parse_KV_file('../.flutter-plugins')
+  plugin_pods.map { |p|
+    symlink = File.join('.symlinks', 'plugins', p[:name])
+    File.symlink(p[:path], symlink)
+    pod p[:name], :path => File.join(symlink, 'ios')
+  }
+end
+
+post_install do |installer|
+  installer.pods_project.targets.each do |target|
+    target.build_configurations.each do |config|
+      config.build_settings['ENABLE_BITCODE'] = 'NO'
+    end
+  end
+end

+ 0 - 15
example/lib/main.dart

@@ -1,4 +1,3 @@
-import 'package:dio/dio.dart';
 import 'package:flustars/flustars.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
@@ -68,20 +67,6 @@ class MainPageState extends State<MainPage> {
   @override
   void initState() {
     super.initState();
-
-    DioUtil.openDebug(); //打开debug模式
-
-    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")
-        .then((BaseResp<List> resp) {
-      print("BaseResp: " + resp.toString());
-    });
-
     widgetUtil.asyncPrepares(true, (_) {
       print("Widget 渲染完成...");
     });

+ 0 - 1
lib/flustars.dart

@@ -5,4 +5,3 @@ export 'src/ui/my_app_bar.dart';
 export 'src/screen_util.dart';
 export 'src/widget_util.dart';
 export 'src/sp_util.dart';
-export 'src/dio_util.dart';

+ 0 - 423
lib/src/dio_util.dart

@@ -1,423 +0,0 @@
-import 'dart:convert';
-import 'dart:io';
-
-import 'package:dio/dio.dart';
-
-/**
- * @Author: thl
- * @GitHub: https://github.com/Sky24n
- * @JianShu: https://www.jianshu.com/u/cbf2ad25d33a
- * @Email: 863764940@qq.com
- * @Description: Dio Util.
- * @Date: 2018/12/19
- */
-
-/// <BaseResp<T> 返回 status code msg data.
-class BaseResp<T> {
-  String status;
-  int code;
-  String msg;
-  T data;
-
-  BaseResp(this.status, this.code, this.msg, this.data);
-
-  @override
-  String toString() {
-    StringBuffer sb = new StringBuffer('{');
-    sb.write("\"status\":\"$status\"");
-    sb.write(",\"code\":$code");
-    sb.write(",\"msg\":\"$msg\"");
-    sb.write(",\"data\":\"$data\"");
-    sb.write('}');
-    return sb.toString();
-  }
-}
-
-/// <BaseRespR<T> 返回 status code msg data Response.
-class BaseRespR<T> {
-  String status;
-  int code;
-  String msg;
-  T data;
-  Response response;
-
-  BaseRespR(this.status, this.code, this.msg, this.data, this.response);
-
-  @override
-  String toString() {
-    StringBuffer sb = new StringBuffer('{');
-    sb.write("\"status\":\"$status\"");
-    sb.write(",\"code\":$code");
-    sb.write(",\"msg\":\"$msg\"");
-    sb.write(",\"data\":\"$data\"");
-    sb.write('}');
-    return sb.toString();
-  }
-}
-
-/// 请求方法.
-class Method {
-  static final String get = "GET";
-  static final String post = "POST";
-  static final String put = "PUT";
-  static final String head = "HEAD";
-  static final String delete = "DELETE";
-  static final String patch = "PATCH";
-}
-
-///Http配置.
-class HttpConfig {
-  /// constructor.
-  HttpConfig({
-    this.status,
-    this.code,
-    this.msg,
-    this.data,
-    this.options,
-    this.pem,
-    this.pKCSPath,
-    this.pKCSPwd,
-  });
-
-  /// BaseResp [String status]字段 key, 默认:status.
-  String status;
-
-  /// BaseResp [int code]字段 key, 默认:errorCode.
-  String code;
-
-  /// BaseResp [String msg]字段 key, 默认:errorMsg.
-  String msg;
-
-  /// BaseResp [T data]字段 key, 默认:data.
-  String data;
-
-  /// Options.
-  Options options;
-
-  /// 详细使用请查看dio官网 https://github.com/flutterchina/dio/blob/flutter/README-ZH.md#Https证书校验.
-  /// PEM证书内容.
-  String pem;
-
-  /// 详细使用请查看dio官网 https://github.com/flutterchina/dio/blob/flutter/README-ZH.md#Https证书校验.
-  /// PKCS12 证书路径.
-  String pKCSPath;
-
-  /// 详细使用请查看dio官网 https://github.com/flutterchina/dio/blob/flutter/README-ZH.md#Https证书校验.
-  /// PKCS12 证书密码.
-  String pKCSPwd;
-}
-
-/// 单例 DioUtil.
-/// debug模式下可以打印请求日志. DioUtil.openDebug().
-/// dio详细使用请查看dio官网(https://github.com/flutterchina/dio).
-class DioUtil {
-  static final DioUtil _singleton = DioUtil._init();
-  static Dio _dio;
-
-  /// BaseResp [String status]字段 key, 默认:status.
-  String _statusKey = "status";
-
-  /// BaseResp [int code]字段 key, 默认:errorCode.
-  String _codeKey = "errorCode";
-
-  /// BaseResp [String msg]字段 key, 默认:errorMsg.
-  String _msgKey = "errorMsg";
-
-  /// BaseResp [T data]字段 key, 默认:data.
-  String _dataKey = "data";
-
-  /// Options.
-  Options _options = getDefOptions();
-
-  /// PEM证书内容.
-  String _pem;
-
-  /// PKCS12 证书路径.
-  String _pKCSPath;
-
-  /// PKCS12 证书密码.
-  String _pKCSPwd;
-
-  /// 是否是debug模式.
-  static bool _isDebug = false;
-
-  static DioUtil getInstance() {
-    return _singleton;
-  }
-
-  factory DioUtil() {
-    return _singleton;
-  }
-
-  DioUtil._init() {
-    _dio = new Dio(_options);
-  }
-
-  /// 打开debug模式.
-  static void openDebug() {
-    _isDebug = true;
-  }
-
-  /// set Config.
-  void setConfig(HttpConfig config) {
-    _statusKey = config.status ?? _statusKey;
-    _codeKey = config.code ?? _codeKey;
-    _msgKey = config.msg ?? _msgKey;
-    _dataKey = config.data ?? _dataKey;
-    _mergeOption(config.options);
-    _pem = config.pem ?? _pem;
-    if (_dio != null) {
-      _dio.options = _options;
-      if (_pem != null) {
-        _dio.onHttpClientCreate = (HttpClient client) {
-          client.badCertificateCallback =
-              (X509Certificate cert, String host, int port) {
-            if (cert.pem == _pem) {
-              // 证书一致,则放行
-              return true;
-            }
-            return false;
-          };
-        };
-      }
-      if (_pKCSPath != null) {
-        _dio.onHttpClientCreate = (HttpClient client) {
-          SecurityContext sc = new SecurityContext();
-          //file为证书路径
-          sc.setTrustedCertificates(_pKCSPath, password: _pKCSPwd);
-          HttpClient httpClient = new HttpClient(context: sc);
-          return httpClient;
-        };
-      }
-    }
-  }
-
-  /// Make http request with options.
-  /// [method] The request method.
-  /// [path] The url path.
-  /// [data] The request data
-  /// [options] The request options.
-  /// <BaseResp<T> 返回 status code msg data .
-  Future<BaseResp<T>> request<T>(String method, String path,
-      {data, Options options, CancelToken cancelToken}) async {
-    Response response = await _dio.request(path,
-        data: data,
-        options: _checkOptions(method, options),
-        cancelToken: cancelToken);
-    _printHttpLog(response);
-    String _status;
-    int _code;
-    String _msg;
-    T _data;
-    if (response.statusCode == HttpStatus.ok ||
-        response.statusCode == HttpStatus.created) {
-      try {
-        if (response.data is Map) {
-          _status = (response.data[_statusKey] is int)
-              ? response.data[_statusKey].toString()
-              : response.data[_statusKey];
-          _code = (response.data[_codeKey] is String)
-              ? int.tryParse(response.data[_codeKey])
-              : response.data[_codeKey];
-          _msg = response.data[_msgKey];
-          _data = response.data[_dataKey];
-        } else {
-          Map<String, dynamic> _dataMap = _decodeData(response);
-          _status = (_dataMap[_statusKey] is int)
-              ? _dataMap[_statusKey].toString()
-              : _dataMap[_statusKey];
-          _code = (_dataMap[_codeKey] is String)
-              ? int.tryParse(_dataMap[_codeKey])
-              : _dataMap[_codeKey];
-          _msg = _dataMap[_msgKey];
-          _data = _dataMap[_dataKey];
-        }
-        return new BaseResp(_status, _code, _msg, _data);
-      } catch (e) {
-        return new Future.error(new DioError(
-          response: response,
-          message: "data parsing exception...",
-          type: DioErrorType.RESPONSE,
-        ));
-      }
-    }
-    return new Future.error(new DioError(
-      response: response,
-      message: "statusCode: $response.statusCode, service error",
-      type: DioErrorType.RESPONSE,
-    ));
-  }
-
-  /// Make http request with options.
-  /// [method] The request method.
-  /// [path] The url path.
-  /// [data] The request data
-  /// [options] The request options.
-  /// <BaseRespR<T> 返回 status code msg data  Response.
-  Future<BaseRespR<T>> requestR<T>(String method, String path,
-      {data, Options options, CancelToken cancelToken}) async {
-    Response response = await _dio.request(path,
-        data: data,
-        options: _checkOptions(method, options),
-        cancelToken: cancelToken);
-    _printHttpLog(response);
-    String _status;
-    int _code;
-    String _msg;
-    T _data;
-    if (response.statusCode == HttpStatus.ok ||
-        response.statusCode == HttpStatus.created) {
-      try {
-        if (response.data is Map) {
-          _status = (response.data[_statusKey] is int)
-              ? response.data[_statusKey].toString()
-              : response.data[_statusKey];
-          _code = (response.data[_codeKey] is String)
-              ? int.tryParse(response.data[_codeKey])
-              : response.data[_codeKey];
-          _msg = response.data[_msgKey];
-          _data = response.data[_dataKey];
-        } else {
-          Map<String, dynamic> _dataMap = _decodeData(response);
-          _status = (_dataMap[_statusKey] is int)
-              ? _dataMap[_statusKey].toString()
-              : _dataMap[_statusKey];
-          _code = (_dataMap[_codeKey] is String)
-              ? int.tryParse(_dataMap[_codeKey])
-              : _dataMap[_codeKey];
-          _msg = _dataMap[_msgKey];
-          _data = _dataMap[_dataKey];
-        }
-        return new BaseRespR(_status, _code, _msg, _data, response);
-      } catch (e) {
-        return new Future.error(new DioError(
-          response: response,
-          message: "data parsing exception...",
-          type: DioErrorType.RESPONSE,
-        ));
-      }
-    }
-    return new Future.error(new DioError(
-      response: response,
-      message: "statusCode: $response.statusCode, service error",
-      type: DioErrorType.RESPONSE,
-    ));
-  }
-
-  /// Download the file and save it in local. The default http method is "GET",you can custom it by [Options.method].
-  /// [urlPath]: The file url.
-  /// [savePath]: The path to save the downloading file later.
-  /// [onProgress]: The callback to listen downloading progress.please refer to [OnDownloadProgress].
-  Future<Response> download(
-    String urlPath,
-    savePath, {
-    OnDownloadProgress onProgress,
-    CancelToken cancelToken,
-    data,
-    Options options,
-  }) {
-    return _dio.download(urlPath, savePath,
-        onProgress: onProgress,
-        cancelToken: cancelToken,
-        data: data,
-        options: options);
-  }
-
-  /// decode response data.
-  Map<String, dynamic> _decodeData(Response response) {
-    if (response == null ||
-        response.data == null ||
-        response.data.toString().isEmpty) {
-      return new Map();
-    }
-    return json.decode(response.data.toString());
-  }
-
-  /// check Options.
-  Options _checkOptions(method, options) {
-    if (options == null) {
-      options = new Options();
-    }
-    options.method = method;
-    return options;
-  }
-
-  /// merge Option.
-  void _mergeOption(Options opt) {
-    _options.method = opt.method ?? _options.method;
-    _options.headers = (new Map.from(_options.headers))..addAll(opt.headers);
-    _options.baseUrl = opt.baseUrl ?? _options.baseUrl;
-    _options.connectTimeout = opt.connectTimeout ?? _options.connectTimeout;
-    _options.receiveTimeout = opt.receiveTimeout ?? _options.receiveTimeout;
-    _options.responseType = opt.responseType ?? _options.responseType;
-    _options.data = opt.data ?? _options.data;
-    _options.extra = (new Map.from(_options.extra))..addAll(opt.extra);
-    _options.contentType = opt.contentType ?? _options.contentType;
-    _options.validateStatus = opt.validateStatus ?? _options.validateStatus;
-    _options.followRedirects = opt.followRedirects ?? _options.followRedirects;
-  }
-
-  /// print Http Log.
-  void _printHttpLog(Response response) {
-    if (!_isDebug) {
-      return;
-    }
-    try {
-      print("----------------Http Log----------------" +
-          "\n[statusCode]:   " +
-          response.statusCode.toString() +
-          "\n[request   ]:   " +
-          _getOptionsStr(response.request));
-      _printDataStr("reqdata ", response.request.data);
-      _printDataStr("response", response.data);
-    } catch (ex) {
-      print("Http Log" + " error......");
-    }
-  }
-
-  /// get Options Str.
-  String _getOptionsStr(Options request) {
-    return "method: " +
-        request.method +
-        "  baseUrl: " +
-        request.baseUrl +
-        "  path: " +
-        request.path;
-  }
-
-  /// print Data Str.
-  void _printDataStr(String tag, Object value) {
-    String da = value.toString();
-    while (da.isNotEmpty) {
-      if (da.length > 512) {
-        print("[$tag  ]:   " + da.substring(0, 512));
-        da = da.substring(512, da.length);
-      } else {
-        print("[$tag  ]:   " + da);
-        da = "";
-      }
-    }
-  }
-
-  /// get dio.
-  Dio getDio() {
-    return _dio;
-  }
-
-  /// create new dio.
-  static Dio createNewDio([Options options]) {
-    options = options ?? getDefOptions();
-    Dio dio = new Dio(options);
-    return dio;
-  }
-
-  /// get Def Options.
-  static Options getDefOptions() {
-    Options options = new Options();
-    options.contentType =
-        ContentType.parse("application/x-www-form-urlencoded");
-    options.connectTimeout = 1000 * 10;
-    options.receiveTimeout = 1000 * 20;
-    return options;
-  }
-}

+ 2 - 4
pubspec.yaml

@@ -1,6 +1,6 @@
 name: flustars
-description: Flutter common utils library. DioUtil, SpUtil, ScreenUtil, WidgetUtil.
-version: 0.1.8
+description: Flutter common utils library. ScreenUtil, SpUtil, WidgetUtil.
+version: 0.1.9
 author: thl <863764940@qq.com>
 homepage: https://github.com/Sky24n/flustars
 
@@ -15,8 +15,6 @@ dependencies:
   synchronized: ^1.5.3
   # https://github.com/flutter/plugins/tree/master/packages/shared_preferences
   shared_preferences: ^0.4.3
-  # https://github.com/flutterchina/dio
-  dio: ^1.0.13
 
 
 # For information on the generic Dart part of this file, see the