Skip to content

Commit

Permalink
2.0.4版本 remove WidgetsBinding.instance.addPostFrameCallback was repla…
Browse files Browse the repository at this point in the history
…ced by await Future.delayed(Duration(milliseconds: 500));
  • Loading branch information
519430378qqcom committed Jul 11, 2022
1 parent bbda08b commit 30f29bc
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 27 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions example/lib/http_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 7 additions & 4 deletions lib/http_log_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class _HttpLogListWidgetState extends State<HttpLogListWidget> {
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),
),
),
),
Expand All @@ -59,7 +60,8 @@ class _HttpLogListWidgetState extends State<HttpLogListWidget> {
child: Align(
child: Text(
'clear',
style: theme.textTheme.caption!.copyWith(fontWeight: FontWeight.bold),
style: theme.textTheme.caption!
.copyWith(fontWeight: FontWeight.bold),
),
),
),
Expand Down Expand Up @@ -89,8 +91,9 @@ class _HttpLogListWidgetState extends State<HttpLogListWidget> {
///格式化请求时间
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,
Expand Down
9 changes: 6 additions & 3 deletions lib/interceptor/dio_log_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)}');
}
}
Expand Down
11 changes: 7 additions & 4 deletions lib/overlay_draggable_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

///关闭悬浮按钮
Expand Down
3 changes: 2 additions & 1 deletion lib/page/log_request_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class LogRequestWidget extends StatefulWidget {
_LogRequestWidgetState createState() => _LogRequestWidgetState();
}

class _LogRequestWidgetState extends State<LogRequestWidget> with AutomaticKeepAliveClientMixin {
class _LogRequestWidgetState extends State<LogRequestWidget>
with AutomaticKeepAliveClientMixin {
late TextEditingController _urlController;
late TextEditingController _cookieController;
late TextEditingController _paramController;
Expand Down
3 changes: 2 additions & 1 deletion lib/page/log_response_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class LogResponseWidget extends StatefulWidget {
_LogResponseWidgetState createState() => _LogResponseWidgetState();
}

class _LogResponseWidgetState extends State<LogResponseWidget> with AutomaticKeepAliveClientMixin {
class _LogResponseWidgetState extends State<LogResponseWidget>
with AutomaticKeepAliveClientMixin {
bool isShowAll = false;
double fontSize = 14;
@override
Expand Down
15 changes: 10 additions & 5 deletions lib/page/log_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class LogWidget extends StatefulWidget {
_LogWidgetState createState() => _LogWidgetState();
}

class _LogWidgetState extends State<LogWidget> with SingleTickerProviderStateMixin {
class _LogWidgetState extends State<LogWidget>
with SingleTickerProviderStateMixin {
final List<Tab> tabs = <Tab>[
new Tab(text: "request"),
new Tab(text: "response"),
Expand Down Expand Up @@ -65,9 +66,12 @@ class _LogWidgetState extends State<LogWidget> 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'),
],
),
);
Expand All @@ -82,6 +86,7 @@ class _LogWidgetState extends State<LogWidget> 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);
}
}
7 changes: 4 additions & 3 deletions lib/utils/log_pool_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
});
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 30f29bc

Please sign in to comment.