├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── android └── app │ └── src │ └── main │ └── java │ └── io │ └── flutter │ └── plugins │ └── GeneratedPluginRegistrant.java ├── dio_util.iml ├── json ├── base.json ├── base2.json └── list.json ├── lib ├── dio_util.dart └── src │ ├── index.dart │ ├── method.dart │ ├── my_interceptor.dart │ ├── my_transformer.dart │ └── processor.dart ├── pubspec.lock ├── pubspec.yaml └── test └── dio_util_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | ios/.generated/ 9 | ios/Flutter/Generated.xcconfig 10 | ios/Runner/GeneratedPluginRegistrant.* 11 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 8661d8aecd626f7f57ccbcb735553edc05a2e713 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.0.1] - TODO: Add release date. 2 | 3 | * TODO: Describe initial release. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | TODO: Add your license here. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dio_util 2 | 3 | A new Flutter package. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Dart 8 | [package](https://flutter.io/developing-packages/), 9 | a library module containing code that can be shared easily across 10 | multiple Flutter or Dart projects. 11 | 12 | For help getting started with Flutter, view our 13 | [online documentation](https://flutter.io/docs), which offers tutorials, 14 | samples, guidance on mobile development, and a full API reference. 15 | -------------------------------------------------------------------------------- /android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java: -------------------------------------------------------------------------------- 1 | package io.flutter.plugins; 2 | 3 | import io.flutter.plugin.common.PluginRegistry; 4 | 5 | /** 6 | * Generated file. Do not edit. 7 | */ 8 | public final class GeneratedPluginRegistrant { 9 | public static void registerWith(PluginRegistry registry) { 10 | if (alreadyRegisteredWith(registry)) { 11 | return; 12 | } 13 | } 14 | 15 | private static boolean alreadyRegisteredWith(PluginRegistry registry) { 16 | final String key = GeneratedPluginRegistrant.class.getCanonicalName(); 17 | if (registry.hasPlugin(key)) { 18 | return true; 19 | } 20 | registry.registrarFor(key); 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /dio_util.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /json/base.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 1, 3 | "msg": "success", 4 | "data": { 5 | "first": "first", 6 | "second": "second" 7 | } 8 | } -------------------------------------------------------------------------------- /json/base2.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 1, 3 | "msg": "success", 4 | "data": { 5 | "third": "third", 6 | "fourth": "fourth" 7 | } 8 | } -------------------------------------------------------------------------------- /json/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 1, 3 | "msg": "success", 4 | "data": [ 5 | { 6 | "first": "first1", 7 | "second": "second1" 8 | }, 9 | { 10 | "first": "first2", 11 | "second": "second2" 12 | }, 13 | { 14 | "first": "first3", 15 | "second": "second3" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /lib/dio_util.dart: -------------------------------------------------------------------------------- 1 | library dio_util; 2 | 3 | export 'src/processor.dart'; 4 | export 'src/method.dart'; 5 | export 'src/index.dart'; 6 | -------------------------------------------------------------------------------- /lib/src/index.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'package:dio/dio.dart'; 3 | import 'package:dio_util/src/my_interceptor.dart'; 4 | import 'package:dio_util/src/my_transformer.dart'; 5 | import 'package:dio_util/src/processor.dart'; 6 | 7 | class DioUtil { 8 | static final DioUtil _singleton = DioUtil._init(); 9 | bool _isDebug = !bool.fromEnvironment("dart.vm.product"); 10 | Dio _dio; 11 | // 默认配置 12 | BaseOptions _baseOptions = BaseOptions( 13 | contentType: ContentType.parse("application/x-www-form-urlencoded"), 14 | connectTimeout: 1000 * 10, 15 | receiveTimeout: 1000 * 20, 16 | ); 17 | 18 | DioUtil._init() { 19 | _dio = new Dio(_baseOptions); 20 | _dio.interceptors 21 | ..add(LogInterceptor( 22 | requestBody: _isDebug, responseBody: _isDebug)) // Dio 日志拦截器 23 | ..add(MyInterceptor(_isDebug)); // 自定义拦截器 24 | // 自定义转换器 25 | _dio.transformer = new MyTransformer(); 26 | } 27 | 28 | Dio getDio() { 29 | return _dio; 30 | } 31 | 32 | factory DioUtil() { 33 | return _singleton; 34 | } 35 | 36 | static DioUtil getInstance() { 37 | return _singleton; 38 | } 39 | 40 | /// 添加拦截器 41 | addInterceptor(Interceptor interceptor) { 42 | _dio.interceptors.add(interceptor); 43 | } 44 | 45 | /// 简单处理 普通数据/List数据 46 | request( 47 | method, // 请求方法 48 | path, // 地址 49 | Processor processor, // 数据处理器 50 | {data, // 请求参数 51 | queryParameters, // dio 2.x get参数 like: api/test?id=12&name=test 52 | option, // 配置参数 53 | cancelToken, // 取消 54 | onSendProgress, // 请求进度回调 55 | onReceiveProgress // 接手进度回调 56 | }) async { 57 | try { 58 | Response response = await _dio.request(path, 59 | data: data, 60 | options: _checkOptions(method, option), 61 | queryParameters: queryParameters, 62 | onSendProgress: onSendProgress, 63 | cancelToken: cancelToken, 64 | onReceiveProgress: onReceiveProgress); 65 | return processor.success(response); 66 | } on DioError catch (e) { 67 | return processor.failed(e); 68 | } 69 | } 70 | 71 | // 选择对应的请求方法 72 | Options _checkOptions(method, options) { 73 | if (options == null) { 74 | options = new Options(); 75 | } 76 | options.method = method; 77 | return options; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /lib/src/method.dart: -------------------------------------------------------------------------------- 1 | const String get = "GET"; 2 | const String post = "POST"; 3 | const String put = "PUT"; 4 | const String head = "HEAD"; 5 | const String delete = "DELETE"; 6 | const String patch = "PATCH"; -------------------------------------------------------------------------------- /lib/src/my_interceptor.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'dart:convert'; 3 | 4 | import 'package:dio/dio.dart'; 5 | 6 | class MyInterceptor extends Interceptor { 7 | bool isDebug; 8 | 9 | MyInterceptor(this.isDebug); 10 | 11 | @override 12 | onRequest(RequestOptions options) { 13 | return options; 14 | } 15 | 16 | @override 17 | onResponse(Response response) { 18 | return response; 19 | } 20 | 21 | Map _decodeData(Response response) { 22 | if (response == null || 23 | response.data == null || 24 | response.data.toString().isEmpty) { 25 | return new Map(); 26 | } 27 | return json.decode(response.data.toString()); 28 | } 29 | 30 | @override 31 | onError(DioError err) { 32 | try { 33 | String message = err.message; 34 | switch (err.response.statusCode) { 35 | case HttpStatus.badRequest: // 400 36 | err.response.data = _decodeData(err.response); 37 | message = err.response.data['msg'] ?? '请求失败,请联系我们'; 38 | break; 39 | case HttpStatus.unauthorized: // 401 40 | err.response.data = _decodeData(err.response); 41 | message = err.response.data['msg'] ?? '未授权,请登录'; 42 | break; 43 | case HttpStatus.forbidden: // 403 44 | message = '拒绝访问'; 45 | break; 46 | case HttpStatus.notFound: // 404 47 | message = '请求地址出错'; 48 | break; 49 | case HttpStatus.requestTimeout: // 408 50 | message = '请求超时'; 51 | break; 52 | case HttpStatus.internalServerError: // 500 53 | message = '服务器内部错误'; 54 | break; 55 | case HttpStatus.notImplemented: // 501 56 | message = '服务未实现'; 57 | break; 58 | case HttpStatus.badGateway: // 502 59 | message = '网关错误'; 60 | break; 61 | case HttpStatus.serviceUnavailable: // 503 62 | message = '服务不可用'; 63 | break; 64 | case HttpStatus.gatewayTimeout: // 504 65 | message = '网关超时'; 66 | break; 67 | } 68 | err.message = message; 69 | return err; 70 | } on TypeError { 71 | err.message = '信息转换错误'; 72 | return err; 73 | } catch (e) { 74 | err.message = '未知错误'; 75 | return err; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /lib/src/my_transformer.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'package:dio/dio.dart'; 3 | import 'package:flutter/foundation.dart'; 4 | 5 | // https://github.com/flutterchina/dio/blob/master/README-ZH.md#%E8%BD%AC%E6%8D%A2%E5%99%A8 6 | class MyTransformer extends DefaultTransformer { 7 | MyTransformer() : super(jsonDecodeCallback: _parseJson); 8 | } 9 | 10 | _parseAndDecode(String response) { 11 | return jsonDecode(response); 12 | } 13 | 14 | _parseJson(String text) { 15 | return compute(_parseAndDecode, text); 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/processor.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'package:dio/dio.dart'; 3 | 4 | /// 对象生成方法 5 | typedef ObjGenerateFun = T Function(Map); 6 | 7 | /// 数据处理器 8 | abstract class Processor { 9 | Processor(this.isList, {this.objGenerateFun}); 10 | bool isList; 11 | ObjGenerateFun objGenerateFun; 12 | // 成功数据处理 13 | success(Response response) => response; 14 | // 失败数据处理 15 | failed(DioError err) => err; 16 | } 17 | 18 | /// 定义 普通数据格式 19 | class BaseResp { 20 | int status; 21 | int code; 22 | String msg; 23 | T data; 24 | BaseResp(this.status, this.code, this.msg, this.data); 25 | 26 | String toString() { 27 | StringBuffer sb = new StringBuffer('{'); 28 | sb.write("\"status\":\"$status\""); 29 | sb.write(",\"code\":$code"); 30 | sb.write(",\"msg\":\"$msg\""); 31 | sb.write(",\"data\":\"$data\""); 32 | sb.write('}'); 33 | return sb.toString(); 34 | } 35 | } 36 | 37 | /// 定义 List数据格式 38 | class BaseRespList { 39 | int status; 40 | int code; 41 | String msg; 42 | List data; 43 | BaseRespList(this.status, this.code, this.msg, this.data); 44 | 45 | @override 46 | String toString() { 47 | StringBuffer sb = new StringBuffer('{'); 48 | sb.write("\"status\":\"$status\""); 49 | sb.write(",\"code\":$code"); 50 | sb.write(",\"msg\":\"$msg\""); 51 | sb.write(",\"data\":\"$data\""); 52 | sb.write('}'); 53 | return sb.toString(); 54 | } 55 | } 56 | 57 | /// 实现默认处理器 58 | class BaseProcessor extends Processor { 59 | BaseProcessor(bool isList, {ObjGenerateFun fun}) 60 | : super(isList, objGenerateFun: fun); 61 | 62 | @override 63 | ObjGenerateFun get objGenerateFun => super.objGenerateFun; 64 | 65 | // 转换json 66 | Map decodeData(Response response) { 67 | if (response == null || 68 | response.data == null || 69 | response.data.toString().isEmpty) { 70 | return new Map(); 71 | } 72 | return json.decode(response.data.toString()); 73 | } 74 | 75 | @override 76 | success(Response response) { 77 | int _status = response.statusCode; 78 | int _code; 79 | String _msg; 80 | // List数据处理 [{...},{...}] 81 | if (isList) { 82 | List _data = new List(); 83 | if (response.data is Map) { 84 | _code = response.data['code']; 85 | _msg = response.data['msg']; 86 | if (T.toString() == 'dynamic') { 87 | _data = response.data['data']; 88 | } else { 89 | if (response.data['data'] != null) { 90 | _data = (response.data['data'] as List) 91 | .map((v) => objGenerateFun(v)) 92 | .toList(); 93 | } 94 | } 95 | } else { 96 | Map _dataMap = decodeData(response); 97 | _code = _dataMap['code']; 98 | _msg = _dataMap['msg']; 99 | if (T.toString() == 'dynamic') { 100 | _data = _dataMap['data']; 101 | } else { 102 | if (objGenerateFun == null) { 103 | throw Exception('you need add ObjGenerateFun or remove T'); 104 | } 105 | if (_dataMap['data'] != null) { 106 | _data = (_dataMap['data'] as List) 107 | .map((v) => objGenerateFun(v)) 108 | .toList(); 109 | } 110 | } 111 | } 112 | return BaseRespList(_status, _code, _msg, _data); 113 | } else { 114 | // 普通数据处理 {...} 115 | T _data; 116 | if (response.data is Map) { 117 | _code = response.data['code']; 118 | _msg = response.data['msg']; 119 | if (T.toString() == 'dynamic') { 120 | _data = response.data['data']; 121 | } else { 122 | _data = objGenerateFun(response.data['data']); 123 | } 124 | } else { 125 | Map _dataMap = decodeData(response); 126 | _code = _dataMap['code']; 127 | _msg = _dataMap['msg']; 128 | if (T.toString() == 'dynamic') { 129 | _data = _dataMap['data']; 130 | } else { 131 | _data = objGenerateFun(_dataMap['data']); 132 | } 133 | } 134 | return BaseResp(_status, _code, _msg, _data); 135 | } 136 | } 137 | 138 | @override 139 | failed(DioError err) { 140 | int _status = err.response.statusCode; 141 | String _msg = err.message; 142 | if (isList) { 143 | return BaseRespList(_status, -1, _msg, []); 144 | } 145 | return BaseResp(_status, -1, _msg, null); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://www.dartlang.org/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.flutter-io.cn" 9 | source: hosted 10 | version: "2.0.8" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.flutter-io.cn" 16 | source: hosted 17 | version: "1.0.4" 18 | charcode: 19 | dependency: transitive 20 | description: 21 | name: charcode 22 | url: "https://pub.flutter-io.cn" 23 | source: hosted 24 | version: "1.1.2" 25 | collection: 26 | dependency: transitive 27 | description: 28 | name: collection 29 | url: "https://pub.flutter-io.cn" 30 | source: hosted 31 | version: "1.14.11" 32 | cookie_jar: 33 | dependency: transitive 34 | description: 35 | name: cookie_jar 36 | url: "https://pub.flutter-io.cn" 37 | source: hosted 38 | version: "1.0.0" 39 | dio: 40 | dependency: "direct main" 41 | description: 42 | name: dio 43 | url: "https://pub.flutter-io.cn" 44 | source: hosted 45 | version: "2.1.3" 46 | flutter: 47 | dependency: "direct main" 48 | description: flutter 49 | source: sdk 50 | version: "0.0.0" 51 | flutter_test: 52 | dependency: "direct dev" 53 | description: flutter 54 | source: sdk 55 | version: "0.0.0" 56 | matcher: 57 | dependency: transitive 58 | description: 59 | name: matcher 60 | url: "https://pub.flutter-io.cn" 61 | source: hosted 62 | version: "0.12.3+1" 63 | meta: 64 | dependency: transitive 65 | description: 66 | name: meta 67 | url: "https://pub.flutter-io.cn" 68 | source: hosted 69 | version: "1.1.6" 70 | path: 71 | dependency: transitive 72 | description: 73 | name: path 74 | url: "https://pub.flutter-io.cn" 75 | source: hosted 76 | version: "1.6.2" 77 | pedantic: 78 | dependency: transitive 79 | description: 80 | name: pedantic 81 | url: "https://pub.flutter-io.cn" 82 | source: hosted 83 | version: "1.4.0" 84 | quiver: 85 | dependency: transitive 86 | description: 87 | name: quiver 88 | url: "https://pub.flutter-io.cn" 89 | source: hosted 90 | version: "2.0.1" 91 | sky_engine: 92 | dependency: transitive 93 | description: flutter 94 | source: sdk 95 | version: "0.0.99" 96 | source_span: 97 | dependency: transitive 98 | description: 99 | name: source_span 100 | url: "https://pub.flutter-io.cn" 101 | source: hosted 102 | version: "1.5.4" 103 | stack_trace: 104 | dependency: transitive 105 | description: 106 | name: stack_trace 107 | url: "https://pub.flutter-io.cn" 108 | source: hosted 109 | version: "1.9.3" 110 | stream_channel: 111 | dependency: transitive 112 | description: 113 | name: stream_channel 114 | url: "https://pub.flutter-io.cn" 115 | source: hosted 116 | version: "1.6.8" 117 | string_scanner: 118 | dependency: transitive 119 | description: 120 | name: string_scanner 121 | url: "https://pub.flutter-io.cn" 122 | source: hosted 123 | version: "1.0.4" 124 | term_glyph: 125 | dependency: transitive 126 | description: 127 | name: term_glyph 128 | url: "https://pub.flutter-io.cn" 129 | source: hosted 130 | version: "1.1.0" 131 | test_api: 132 | dependency: transitive 133 | description: 134 | name: test_api 135 | url: "https://pub.flutter-io.cn" 136 | source: hosted 137 | version: "0.2.2" 138 | typed_data: 139 | dependency: transitive 140 | description: 141 | name: typed_data 142 | url: "https://pub.flutter-io.cn" 143 | source: hosted 144 | version: "1.1.6" 145 | vector_math: 146 | dependency: transitive 147 | description: 148 | name: vector_math 149 | url: "https://pub.flutter-io.cn" 150 | source: hosted 151 | version: "2.0.8" 152 | sdks: 153 | dart: ">=2.1.0 <3.0.0" 154 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dio_util 2 | description: A new Flutter package. 3 | version: 0.0.1 4 | author: CcSimple <840054486@qq.com> 5 | homepage: 6 | 7 | environment: 8 | sdk: ">=2.1.0 <3.0.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | # https://github.com/flutterchina/dio 14 | dio: ^2.1.3 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | 20 | # For information on the generic Dart part of this file, see the 21 | # following page: https://www.dartlang.org/tools/pub/pubspec 22 | 23 | # The following section is specific to Flutter. 24 | flutter: 25 | 26 | # To add assets to your package, add an assets section, like this: 27 | # assets: 28 | # - images/a_dot_burr.jpeg 29 | # - images/a_dot_ham.jpeg 30 | # 31 | # For details regarding assets in packages, see 32 | # https://flutter.io/assets-and-images/#from-packages 33 | # 34 | # An image asset can refer to one or more resolution-specific "variants", see 35 | # https://flutter.io/assets-and-images/#resolution-aware. 36 | 37 | # To add custom fonts to your package, add a fonts section here, 38 | # in this "flutter" section. Each entry in this list should have a 39 | # "family" key with the font family name, and a "fonts" key with a 40 | # list giving the asset and other descriptors for the font. For 41 | # example: 42 | # fonts: 43 | # - family: Schyler 44 | # fonts: 45 | # - asset: fonts/Schyler-Regular.ttf 46 | # - asset: fonts/Schyler-Italic.ttf 47 | # style: italic 48 | # - family: Trajan Pro 49 | # fonts: 50 | # - asset: fonts/TrajanPro.ttf 51 | # - asset: fonts/TrajanPro_Bold.ttf 52 | # weight: 700 53 | # 54 | # For details regarding fonts in packages, see 55 | # https://flutter.io/custom-fonts/#from-packages 56 | -------------------------------------------------------------------------------- /test/dio_util_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | import 'package:dio_util/dio_util.dart'; 3 | 4 | class TestEntity { 5 | String first; 6 | String second; 7 | 8 | TestEntity({this.first, this.second}); 9 | 10 | TestEntity.fromJson(Map json) { 11 | first = json['first']; 12 | second = json['second']; 13 | } 14 | /// 手动实现 或者 使用 FlutterJsonBeanFactory 插件生成 EntityFactory 15 | /// 见下方 16 | static T generateOBJ(json) { 17 | return TestEntity.fromJson(json) as T; 18 | } 19 | 20 | Map toJson() { 21 | final Map data = new Map(); 22 | data['first'] = this.first; 23 | data['second'] = this.second; 24 | return data; 25 | } 26 | } 27 | 28 | class Test2Entity { 29 | String third; 30 | String fourth; 31 | 32 | Test2Entity({this.third, this.fourth}); 33 | 34 | Test2Entity.fromJson(Map json) { 35 | third = json['third']; 36 | fourth = json['fourth']; 37 | } 38 | 39 | Map toJson() { 40 | final Map data = new Map(); 41 | data['third'] = this.third; 42 | data['fourth'] = this.fourth; 43 | return data; 44 | } 45 | } 46 | // 使用 FlutterJsonBeanFactory 插件生成 47 | // https://github.com/zhangruiyu/FlutterJsonBeanFactory 48 | class EntityFactory { 49 | static T generateOBJ(json) { 50 | if (1 == 0) { 51 | return null; 52 | } else if (T.toString() == "TestEntity") { 53 | return TestEntity.fromJson(json) as T; 54 | } else if (T.toString() == "Test2Entity") { 55 | return Test2Entity.fromJson(json) as T; 56 | } else { 57 | return null; 58 | } 59 | } 60 | } 61 | 62 | void main() { 63 | /// 手动实现 类似 generateOBJ 方法 64 | test('util test(简单测试)', () async { 65 | BaseResp res = await DioUtil().request( 66 | get, 67 | 'https://raw.githubusercontent.com/CcSimple/dio_util/master/json/base.json', 68 | BaseProcessor(false,fun: TestEntity.generateOBJ)); 69 | print('----------------------------------'); 70 | print('status: ${res.status}'); 71 | print('code: ${res.code}'); 72 | print('msg: ${res.msg}'); 73 | print('data: ${res.data}'); 74 | print('first: ${res.data.first}'); 75 | print('second: ${res.data.second}'); 76 | print('----------------------------------'); 77 | }); 78 | /// EntityFactory 自动处理 79 | test('util test EntityFactory(测试对象生成方法)', () async { 80 | BaseResp res = await DioUtil().request( 81 | get, 82 | 'https://raw.githubusercontent.com/CcSimple/dio_util/master/json/base2.json', 83 | BaseProcessor(false,fun: EntityFactory.generateOBJ)); 84 | print('----------------------------------'); 85 | print('status: ${res.status}'); 86 | print('code: ${res.code}'); 87 | print('msg: ${res.msg}'); 88 | print('data: ${res.data}'); 89 | print('third: ${res.data.third}'); 90 | print('fourth: ${res.data.fourth}'); 91 | print('----------------------------------'); 92 | }); 93 | /// EntityFactory 自动处理 94 | test('util test list EntityFactory(测试List对象生成方法)', () async { 95 | BaseRespList res = await DioUtil().request( 96 | get, 97 | 'https://raw.githubusercontent.com/CcSimple/dio_util/master/json/list.json', 98 | BaseProcessor(true, fun: EntityFactory.generateOBJ)); 99 | print('----------------------------------'); 100 | print('status: ${res.status}'); 101 | print('code: ${res.code}'); 102 | print('msg: ${res.msg}'); 103 | print('data: ${res.data}'); 104 | print('first: ${res.data.elementAt(0).first}'); 105 | print('second: ${res.data.elementAt(0).second}'); 106 | print('----------------------------------'); 107 | }); 108 | } 109 | --------------------------------------------------------------------------------