diff --git a/lib/service/net.dart b/lib/service/net.dart index 286e1fdd..57f8ab09 100644 --- a/lib/service/net.dart +++ b/lib/service/net.dart @@ -15,6 +15,7 @@ import 'base_model.dart'; /// 自定义枚举 enum Method { get, post } +@Deprecated("net need to be cleaned.") class Net { // 工厂模式 factory Net() => _getInstance(); @@ -47,7 +48,7 @@ class Net { /// 打印拦截器(便于调试) static final interceptors = InterceptorsWrapper( /// 请求发送前处理处理一些事情 - onRequest: (RequestOptions options) { + onRequest: (options, handler) { print("--------------------请求参数---------------------"); print(json.encode(options.headers)); print(options.method); @@ -55,23 +56,23 @@ class Net { print(options.baseUrl + options.path); print(options.data); print("--------------------请求参数---------------------"); - return options; + return handler.next(options); }, /// 在数据响应前做一些预处理 - onResponse: (Response response) { + onResponse: (response, handler) { // Log.i("--------------------响应结果---------------------"); // Log.e("response.statusCode", "${response.statusCode}"); // Log.e("response.data", "${json.encode(response.data)}"); // Log.e("response.headers", "${response.headers}"); // Log.i("--------------------响应结果---------------------"); - return response; + return handler.next(response); }, /// 错误处理 - onError: (DioError e) { + onError: (DioError e, handler) { // Log.e("DioError", "$e"); - return e; + return handler.next(e); }, ); // 单列模式 diff --git a/lib/utils/network/net_util.dart b/lib/utils/network/net_util.dart index 7524708a..a983b5d5 100644 --- a/lib/utils/network/net_util.dart +++ b/lib/utils/network/net_util.dart @@ -3,7 +3,6 @@ import 'dart:io'; import 'package:bot_toast/bot_toast.dart'; import 'package:dio/dio.dart'; import 'package:get/get.dart' hide Response, FormData, MultipartFile; -import 'package:logger/logger.dart'; import 'package:power_logger/power_logger.dart'; import 'package:provider/provider.dart'; @@ -32,14 +31,14 @@ class NetUtil { ); if (_dio == null) _dio = Dio(options); dio.interceptors.add(InterceptorsWrapper( - onRequest: (RequestOptions options) async => options, - onResponse: (Response response) async { + onRequest: (options, handler) async => handler.next(options), + onResponse: (response, handler) async { LoggerData.addData(response); - return response; + return handler.next(response); }, - onError: (DioError error) async { + onError: (error, handler) async { _parseErr(error); - return error; + return handler.next(error); }, )); } @@ -140,17 +139,17 @@ class NetUtil { } switch (err.type) { - case DioErrorType.CONNECT_TIMEOUT: - case DioErrorType.SEND_TIMEOUT: - case DioErrorType.RECEIVE_TIMEOUT: + case DioErrorType.connectTimeout: + case DioErrorType.sendTimeout: + case DioErrorType.receiveTimeout: _makeToast('连接超时'); break; - case DioErrorType.RESPONSE: + case DioErrorType.response: _makeToast('服务器出错'); break; - case DioErrorType.CANCEL: + case DioErrorType.cancel: break; - case DioErrorType.DEFAULT: + case DioErrorType.other: _makeToast('未知错误'); break; } diff --git a/pubspec.lock b/pubspec.lock index cb4f11a2..b90abfde 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -84,7 +84,7 @@ packages: name: auto_size_text url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" + version: "3.0.0-nullsafety.0" auto_size_text_pk: dependency: transitive description: @@ -252,21 +252,21 @@ packages: name: device_info url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.0" + version: "2.0.0" device_info_platform_interface: dependency: transitive description: name: device_info_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "2.0.0" dio: dependency: "direct main" description: name: dio url: "https://pub.flutter-io.cn" source: hosted - version: "3.0.10" + version: "4.0.0-prev3" extended_list_library: dependency: transitive description: @@ -376,7 +376,7 @@ packages: name: flutter_highlight url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.0" + version: "0.7.0" flutter_html: dependency: "direct main" description: @@ -423,7 +423,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.11" + version: "2.0.0" flutter_rating_bar: dependency: "direct main" description: @@ -524,7 +524,7 @@ packages: name: highlight url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.0" + version: "0.7.0" hive: dependency: "direct main" description: @@ -552,14 +552,14 @@ packages: name: http url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.2" + version: "0.13.1" http_parser: dependency: transitive description: name: http_parser url: "https://pub.flutter-io.cn" source: hosted - version: "3.1.4" + version: "4.0.0" image: dependency: transitive description: @@ -573,14 +573,21 @@ packages: name: image_picker url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.7+21" + version: "0.7.3" + image_picker_for_web: + dependency: transitive + description: + name: image_picker_for_web + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.1" + version: "2.0.0" image_stack: dependency: "direct main" description: @@ -715,7 +722,7 @@ packages: name: package_info url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.3+4" + version: "2.0.0" path: dependency: transitive description: @@ -778,7 +785,7 @@ packages: name: pedantic url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.2" + version: "1.11.0" permission_handler: dependency: "direct main" description: @@ -827,14 +834,7 @@ packages: name: power_logger url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.3" - pretty_json: - dependency: transitive - description: - name: pretty_json - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.1.0" + version: "1.0.0-nullsafety.0" process: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 294274ac..71c4136e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: # 权限组件 permission_handler: ^5.0.1+1 # 版本信息 - package_info: ^0.4.1 + package_info: ^2.0.0 #上拉加载 pull_to_refresh: ^1.6.4 # 状态管理 @@ -60,7 +60,7 @@ dependencies: #滑块 flutter_slidable: ^0.5.7 #http - dio: ^3.0.10 + dio: ^4.0.0-prev3 #骨架 shimmer: ^1.1.2 #时间选择 @@ -87,8 +87,8 @@ dependencies: git: url: http://192.168.2.201:8099/zhangmeng/random_character.git - image_picker: ^0.6.7+21 - power_logger: ^0.1.3 + image_picker: ^0.7.3 + power_logger: ^1.0.0-nullsafety.0 flutter_rating_bar: ^3.2.0+1 jpush_flutter: git: