diff --git a/CHANGELOG.md b/CHANGELOG.md index 522a5b8..83d0fca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -## [v2.0.3] - 2021/10/15 +## [v2.0.4] - 2022/07/11 +* remove WidgetsBinding.instance.addPostFrameCallback was replaced by await Future.delayed(Duration(milliseconds: 500)); +## [v2.0.3] - 2021/06/13 * fix flutter 3.0 warning of WidgetsBinding * Add the isError method implementation to LogPoolManager so that request messages defined as errors are displayed in red font -## [v2.0.2] - 2021/10/15 +## [v2.0.2] - 2021/03/22 * fix copy Clipboard error * Response header values can be copied ## [v2.0.1] - 2021/10/15 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6fa75bf --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +all: format check pub +format: + @echo '格式化dart代码---执行|dart format .|命令' + @fvm dart format . +check: + @echo '检查代码---执行|dart analyze .|命令' + @fvm dart analyze . +pub: + @echo '发布插件到pub---执行|packages pub publish --server=https://pub.dev|命令' + @fvm flutter packages pub publish --server=https://pub.dev + diff --git a/README.md b/README.md index 27374f6..f69e223 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ Navigator.of(context).push( LogPoolManager.getInstance().maxCount = 100; ///Add the isError method implementation to LogPoolManager so that request messages defined as errors are displayed in red font LogPoolManager.getInstance().isError = (res) => res.resOptions==null; +///Disabling Log Printing +DioLogInterceptor.enablePrintLog = false; ``` ### Screenshot diff --git a/example/lib/http_utils.dart b/example/lib/http_utils.dart index bf040a7..04bceee 100644 --- a/example/lib/http_utils.dart +++ b/example/lib/http_utils.dart @@ -4,6 +4,7 @@ import 'package:dio_log/dio_log.dart'; Dio dio = Dio(); initHttp() { + DioLogInterceptor.enablePrintLog = false; dio.interceptors.add(DioLogInterceptor()); // LogPoolManager.getInstance().isError = (res) => res.resOptions==null; } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 29fd662..1609079 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -28,8 +28,9 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.1 dio: ^4.0.0 - dio_log: 2.0.3 -# path: ../../dio_log +# dio_log: 2.0.3 + dio_log: + path: ../../dio_log dev_dependencies: flutter_test: diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..0b7ef4a --- /dev/null +++ b/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/rich/fvm/versions/3.0.1" +export "FLUTTER_APPLICATION_PATH=/Users/rich/Documents/flutterplugin/dio_log" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "FLUTTER_BUILD_NAME=2.0.2" +export "FLUTTER_BUILD_NUMBER=2.0.2" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.dart_tool/package_config.json" diff --git a/lib/http_log_list_widget.dart b/lib/http_log_list_widget.dart index 627913d..def0ce6 100644 --- a/lib/http_log_list_widget.dart +++ b/lib/http_log_list_widget.dart @@ -44,7 +44,8 @@ class _HttpLogListWidgetState extends State { child: Align( child: Text( debugBtnIsShow() ? 'close overlay' : 'open overlay', - style: theme.textTheme.caption!.copyWith(fontWeight: FontWeight.bold), + style: theme.textTheme.caption! + .copyWith(fontWeight: FontWeight.bold), ), ), ), @@ -59,7 +60,8 @@ class _HttpLogListWidgetState extends State { child: Align( child: Text( 'clear', - style: theme.textTheme.caption!.copyWith(fontWeight: FontWeight.bold), + style: theme.textTheme.caption! + .copyWith(fontWeight: FontWeight.bold), ), ), ), @@ -89,8 +91,9 @@ class _HttpLogListWidgetState extends State { ///格式化请求时间 var requestTime = getTimeStr1(reqOpt.requestTime!); - Color? textColor = - LogPoolManager.getInstance().isError(item) ? Colors.red : Theme.of(context).textTheme.bodyText1!.color; + Color? textColor = LogPoolManager.getInstance().isError(item) + ? Colors.red + : Theme.of(context).textTheme.bodyText1!.color; return Card( margin: EdgeInsets.all(8), elevation: 6, diff --git a/lib/interceptor/dio_log_interceptor.dart b/lib/interceptor/dio_log_interceptor.dart index 3b6655d..1e1c230 100644 --- a/lib/interceptor/dio_log_interceptor.dart +++ b/lib/interceptor/dio_log_interceptor.dart @@ -47,7 +47,8 @@ class DioLogInterceptor implements Interceptor { ///响应体数据采集 @override - Future onResponse(Response response, ResponseInterceptorHandler handler) async { + Future onResponse( + Response response, ResponseInterceptorHandler handler) async { saveResponse(response); return handler.next(response); } @@ -61,11 +62,13 @@ class DioLogInterceptor implements Interceptor { resOpt.headers = response.headers.map; logManage?.onResponse(resOpt); if (enablePrintLog) { - NetOptions log = LogPoolManager.getInstance().logMap[resOpt.id.toString()]!; + NetOptions log = + LogPoolManager.getInstance().logMap[resOpt.id.toString()]!; print('dio_log: request: url:${log.reqOptions?.url}'); print('dio_log: request: method:${log.reqOptions?.method}'); print('dio_log: request: params:${log.reqOptions?.params}'); - print('dio_log: request: duration:${getTimeStr1(log.reqOptions!.requestTime!)}'); + print( + 'dio_log: request: duration:${getTimeStr1(log.reqOptions!.requestTime!)}'); print('dio_log: response: ${toJson(log.resOptions?.data)}'); } } diff --git a/lib/overlay_draggable_button.dart b/lib/overlay_draggable_button.dart index ee81fce..4490172 100644 --- a/lib/overlay_draggable_button.dart +++ b/lib/overlay_draggable_button.dart @@ -9,15 +9,18 @@ import 'dio_log.dart'; OverlayEntry? itemEntry; ///显示全局悬浮调试按钮 -showDebugBtn(BuildContext context, {Widget? button, Color? btnColor}) { +showDebugBtn(BuildContext context, {Widget? button, Color? btnColor}) async { ///widget第一次渲染完成 - WidgetsBinding.instance.addPostFrameCallback((_) { + try { + await Future.delayed(Duration(milliseconds: 500)); dismissDebugBtn(); - itemEntry = OverlayEntry(builder: (BuildContext context) => button ?? DraggableButtonWidget(btnColor: btnColor)); + itemEntry = OverlayEntry( + builder: (BuildContext context) => + button ?? DraggableButtonWidget(btnColor: btnColor)); ///显示悬浮menu Overlay.of(context)?.insert(itemEntry!); - }); + } catch (e) {} } ///关闭悬浮按钮 diff --git a/lib/page/log_request_widget.dart b/lib/page/log_request_widget.dart index 98e175d..082d9b7 100644 --- a/lib/page/log_request_widget.dart +++ b/lib/page/log_request_widget.dart @@ -15,7 +15,8 @@ class LogRequestWidget extends StatefulWidget { _LogRequestWidgetState createState() => _LogRequestWidgetState(); } -class _LogRequestWidgetState extends State with AutomaticKeepAliveClientMixin { +class _LogRequestWidgetState extends State + with AutomaticKeepAliveClientMixin { late TextEditingController _urlController; late TextEditingController _cookieController; late TextEditingController _paramController; diff --git a/lib/page/log_response_widget.dart b/lib/page/log_response_widget.dart index 3258aae..d9e6022 100644 --- a/lib/page/log_response_widget.dart +++ b/lib/page/log_response_widget.dart @@ -11,7 +11,8 @@ class LogResponseWidget extends StatefulWidget { _LogResponseWidgetState createState() => _LogResponseWidgetState(); } -class _LogResponseWidgetState extends State with AutomaticKeepAliveClientMixin { +class _LogResponseWidgetState extends State + with AutomaticKeepAliveClientMixin { bool isShowAll = false; double fontSize = 14; @override diff --git a/lib/page/log_widget.dart b/lib/page/log_widget.dart index 3db53d3..02a3310 100644 --- a/lib/page/log_widget.dart +++ b/lib/page/log_widget.dart @@ -12,7 +12,8 @@ class LogWidget extends StatefulWidget { _LogWidgetState createState() => _LogWidgetState(); } -class _LogWidgetState extends State with SingleTickerProviderStateMixin { +class _LogWidgetState extends State + with SingleTickerProviderStateMixin { final List tabs = [ new Tab(text: "request"), new Tab(text: "response"), @@ -65,9 +66,12 @@ class _LogWidgetState extends State with SingleTickerProviderStateMix currentIndex: currentIndex, onTap: _bottomTap, items: [ - BottomNavigationBarItem(icon: Icon(Icons.cloud_upload_outlined), label: 'Request'), - BottomNavigationBarItem(icon: Icon(Icons.cloud_download_outlined), label: 'Response'), - BottomNavigationBarItem(icon: Icon(Icons.error_outline), label: 'Error'), + BottomNavigationBarItem( + icon: Icon(Icons.cloud_upload_outlined), label: 'Request'), + BottomNavigationBarItem( + icon: Icon(Icons.cloud_download_outlined), label: 'Response'), + BottomNavigationBarItem( + icon: Icon(Icons.error_outline), label: 'Error'), ], ), ); @@ -82,6 +86,7 @@ class _LogWidgetState extends State with SingleTickerProviderStateMix } void _bottomTap(int value) { - _pageController!.animateToPage(value, duration: Duration(milliseconds: 300), curve: Curves.ease); + _pageController!.animateToPage(value, + duration: Duration(milliseconds: 300), curve: Curves.ease); } } diff --git a/lib/utils/log_pool_manager.dart b/lib/utils/log_pool_manager.dart index 56f9a03..66d08ef 100644 --- a/lib/utils/log_pool_manager.dart +++ b/lib/utils/log_pool_manager.dart @@ -15,7 +15,8 @@ class LogPoolManager { ///存储请求最大数 int maxCount = 50; - ResError isError = (res) => res.errOptions != null || res.resOptions?.statusCode == null; + ResError isError = + (res) => res.errOptions != null || res.resOptions?.statusCode == null; static LogPoolManager? _instance; @@ -55,8 +56,8 @@ class LogPoolManager { var key = response.id.toString(); if (logMap.containsKey(key)) { logMap.update(key, (value) { - response.duration = - response.responseTime!.millisecondsSinceEpoch - value.reqOptions!.requestTime!.millisecondsSinceEpoch; + response.duration = response.responseTime!.millisecondsSinceEpoch - + value.reqOptions!.requestTime!.millisecondsSinceEpoch; value.resOptions = response; return value; }); diff --git a/pubspec.yaml b/pubspec.yaml index dccd1e8..7ea3068 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dio_log -description: HTTP Inspector tool for Dart which can debugging http requests,Currently, DIO based HTTP capture is implemented. -version: 2.0.3 +description: A plug-in that captures requests and views them within the application, providing functions such as request replication and JSON expansion +version: 2.0.4 homepage: https://github.com/flutterplugin/dio_log environment: