From 012a66194f8a7a4bd19f1da61a9e006ce1bd925b Mon Sep 17 00:00:00 2001 From: Spike Date: Wed, 22 Feb 2023 15:05:23 +0800 Subject: [PATCH 1/6] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 7ea3068..3feeb0b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: flutter: sdk: flutter - dio: ^4.0.0 + dio: ^5.0.0 dev_dependencies: flutter_test: From c8778c94f954b96fffcb55f7bfa0263a948b167c Mon Sep 17 00:00:00 2001 From: Spike Date: Wed, 22 Feb 2023 15:10:18 +0800 Subject: [PATCH 2/6] Update overlay_draggable_button.dart --- lib/overlay_draggable_button.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/overlay_draggable_button.dart b/lib/overlay_draggable_button.dart index 4490172..7880fde 100644 --- a/lib/overlay_draggable_button.dart +++ b/lib/overlay_draggable_button.dart @@ -19,8 +19,10 @@ showDebugBtn(BuildContext context, {Widget? button, Color? btnColor}) async { button ?? DraggableButtonWidget(btnColor: btnColor)); ///显示悬浮menu - Overlay.of(context)?.insert(itemEntry!); - } catch (e) {} + Overlay.of(context)!.insert(itemEntry!); + } catch (e) { + debugPrint(e.toString()); + } } ///关闭悬浮按钮 From 770fe50647a78dee5b24a29871b1a0617900c1a2 Mon Sep 17 00:00:00 2001 From: Spike Date: Thu, 4 May 2023 14:58:06 +0800 Subject: [PATCH 3/6] feat: copy cURL --- example/lib/home_page.dart | 3 +- example/lib/http_utils.dart | 11 +++++- example/pubspec.yaml | 2 +- lib/bean/req_options.dart | 13 +++++++ lib/page/log_request_widget.dart | 58 +++++++++++++------------------- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index 363349f..8c571aa 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -26,6 +26,7 @@ class _MyHomePageState extends State { @override void dispose() { + controller.dispose(); super.dispose(); } @@ -40,7 +41,7 @@ class _MyHomePageState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - 'enter the requesr you want to send and press the send button', + 'enter the request you want to send and press the send button', ), TextField( controller: controller, diff --git a/example/lib/http_utils.dart b/example/lib/http_utils.dart index 04bceee..8fa28ec 100644 --- a/example/lib/http_utils.dart +++ b/example/lib/http_utils.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:dio/dio.dart'; import 'package:dio_log/dio_log.dart'; @@ -10,5 +12,12 @@ initHttp() { } httpGet(String url) { - dio.get(url); + dio.get( + url, + queryParameters: {'foo': 'bar'}, + data: jsonEncode({'baz': 'qaz'}), + options: Options( + headers: {'a': 'b'}, + ), + ); } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1609079..efc6f06 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.1 - dio: ^4.0.0 + dio: ^5.0.0 # dio_log: 2.0.3 dio_log: path: ../../dio_log diff --git a/lib/bean/req_options.dart b/lib/bean/req_options.dart index 9e05f58..432607f 100644 --- a/lib/bean/req_options.dart +++ b/lib/bean/req_options.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + ///需要的请求数据类 class ReqOptions { int? id; @@ -18,4 +20,15 @@ class ReqOptions { this.params, this.data, }); + + String get cURL { + final cmd = ['curl']; + cmd.addAll(['-X', method ?? 'GET']); + headers?.forEach((key, value) { + cmd.addAll(['-H', '"$key: $value"']); + }); + if (data != null) cmd.addAll(['-d', jsonEncode(data)]); + cmd.add(url ?? ''); + return cmd.join(' '); + } } diff --git a/lib/page/log_request_widget.dart b/lib/page/log_request_widget.dart index 082d9b7..280945d 100644 --- a/lib/page/log_request_widget.dart +++ b/lib/page/log_request_widget.dart @@ -1,9 +1,10 @@ import 'dart:convert'; import 'package:dio/dio.dart'; -import 'package:dio_log/bean/net_options.dart'; import 'package:flutter/material.dart'; +import 'package:dio_log/bean/net_options.dart'; + import '../dio_log.dart'; class LogRequestWidget extends StatefulWidget { @@ -15,31 +16,7 @@ class LogRequestWidget extends StatefulWidget { _LogRequestWidgetState createState() => _LogRequestWidgetState(); } -class _LogRequestWidgetState extends State - with AutomaticKeepAliveClientMixin { - late TextEditingController _urlController; - late TextEditingController _cookieController; - late TextEditingController _paramController; - late TextEditingController _bodyController; - bool reqFail = false; - @override - void initState() { - _urlController = TextEditingController(); - _cookieController = TextEditingController(); - _paramController = TextEditingController(); - _bodyController = TextEditingController(); - super.initState(); - } - - @override - void dispose() { - _bodyController.dispose(); - _paramController.dispose(); - _urlController.dispose(); - _cookieController.dispose(); - super.dispose(); - } - +class _LogRequestWidgetState extends State with AutomaticKeepAliveClientMixin { @override Widget build(BuildContext context) { super.build(context); @@ -61,15 +38,26 @@ class _LogRequestWidgetState extends State 'Tip: long press a key to copy the value to the clipboard', style: TextStyle(fontSize: 10, color: Colors.red), ), - ElevatedButton( - onPressed: () { - copyClipboard( - context, - 'url:${reqOpt.url}\nmethod:${reqOpt.method}\nrequestTime:$requestTime\nresponseTime:$responseTime\n' - 'duration:${resOpt?.duration ?? 0}ms\n${dataFormat(reqOpt.data)}' - '\nparams:${toJson(reqOpt.params)}\nheader:${reqOpt.headers}'); - }, - child: Text('copy all'), + Row( + children: [ + ElevatedButton( + onPressed: () { + copyClipboard( + context, + 'url:${reqOpt.url}\nmethod:${reqOpt.method}\nrequestTime:$requestTime\nresponseTime:$responseTime\n' + 'duration:${resOpt?.duration ?? 0}ms\n${dataFormat(reqOpt.data)}' + '\nparams:${toJson(reqOpt.params)}\nheader:${reqOpt.headers}'); + }, + child: Text('copy all'), + ), + SizedBox(width: 8), + ElevatedButton( + onPressed: () { + copyClipboard(context, reqOpt.cURL); + }, + child: Text('copy cURL'), + ), + ], ), _buildKeyValue('url', reqOpt.url), _buildKeyValue('method', reqOpt.method), From 71fd2a0db4880d9a67fb9f9a71f99eeddbb9ff79 Mon Sep 17 00:00:00 2001 From: Spike Date: Thu, 4 May 2023 16:38:11 +0800 Subject: [PATCH 4/6] fix: json data --- lib/bean/req_options.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bean/req_options.dart b/lib/bean/req_options.dart index 432607f..c98b0ba 100644 --- a/lib/bean/req_options.dart +++ b/lib/bean/req_options.dart @@ -27,7 +27,7 @@ class ReqOptions { headers?.forEach((key, value) { cmd.addAll(['-H', '"$key: $value"']); }); - if (data != null) cmd.addAll(['-d', jsonEncode(data)]); + if (data != null) cmd.addAll(['-d', '${jsonEncode(data)}']); cmd.add(url ?? ''); return cmd.join(' '); } From 5d86d4aba7a2f2b974f7021795f1e5468d1a0278 Mon Sep 17 00:00:00 2001 From: Spike Date: Fri, 2 Jun 2023 14:42:46 +0800 Subject: [PATCH 5/6] fix: add quote for request body --- lib/bean/req_options.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bean/req_options.dart b/lib/bean/req_options.dart index c98b0ba..8b25d2f 100644 --- a/lib/bean/req_options.dart +++ b/lib/bean/req_options.dart @@ -27,7 +27,7 @@ class ReqOptions { headers?.forEach((key, value) { cmd.addAll(['-H', '"$key: $value"']); }); - if (data != null) cmd.addAll(['-d', '${jsonEncode(data)}']); + if (data != null) cmd.addAll(['-d', '\'${jsonEncode(data)}\'']); cmd.add(url ?? ''); return cmd.join(' '); } From 0095fe07f2de92aef4ee476bc9ef205346450196 Mon Sep 17 00:00:00 2001 From: spike Date: Sun, 13 Oct 2024 19:00:56 +0800 Subject: [PATCH 6/6] fix(deps)!: upgrade dio --- .dart_tool/version | 1 - .gitignore | 2 ++ android/local.properties | 2 ++ example/lib/home_page.dart | 2 +- example/pubspec.yaml | 2 +- lib/http_log_list_widget.dart | 33 +++++++++----------------------- lib/page/log_request_widget.dart | 3 ++- 7 files changed, 17 insertions(+), 28 deletions(-) delete mode 100644 .dart_tool/version create mode 100644 android/local.properties diff --git a/.dart_tool/version b/.dart_tool/version deleted file mode 100644 index 13d683c..0000000 --- a/.dart_tool/version +++ /dev/null @@ -1 +0,0 @@ -3.0.1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 20bca64..bbb0f9f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ workspace.xml .dart_tool .fvm .vscode +.DS_Store +.dart_tool \ No newline at end of file diff --git a/android/local.properties b/android/local.properties new file mode 100644 index 0000000..1f18c1a --- /dev/null +++ b/android/local.properties @@ -0,0 +1,2 @@ +sdk.dir=/Users/pingyangliao/Library/Android/sdk +flutter.sdk=/Users/pingyangliao/SDK/flutter \ No newline at end of file diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index 8c571aa..8ead437 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'http_utils.dart'; class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({super.key, required this.title}); final String title; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index efc6f06..54794ab 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,7 +18,7 @@ description: example of dio log version: 1.0.0+1 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: diff --git a/lib/http_log_list_widget.dart b/lib/http_log_list_widget.dart index def0ce6..9b3f35c 100644 --- a/lib/http_log_list_widget.dart +++ b/lib/http_log_list_widget.dart @@ -30,8 +30,8 @@ class _HttpLogListWidgetState extends State { elevation: 1.0, iconTheme: theme.iconTheme, actions: [ - InkWell( - onTap: () { + FilledButton( + onPressed: () { if (debugBtnIsShow()) { dismissDebugBtn(); } else { @@ -39,32 +39,16 @@ class _HttpLogListWidgetState extends State { } setState(() {}); }, - child: Container( - padding: EdgeInsets.symmetric(horizontal: 8), - child: Align( - child: Text( - debugBtnIsShow() ? 'close overlay' : 'open overlay', - style: theme.textTheme.caption! - .copyWith(fontWeight: FontWeight.bold), - ), - ), + child: Text( + debugBtnIsShow() ? 'close overlay' : 'open overlay', ), ), - InkWell( - onTap: () { + FilledButton( + onPressed: () { LogPoolManager.getInstance().clear(); setState(() {}); }, - child: Container( - padding: EdgeInsets.symmetric(horizontal: 8), - child: Align( - child: Text( - 'clear', - style: theme.textTheme.caption! - .copyWith(fontWeight: FontWeight.bold), - ), - ), - ), + child: Text('clear'), ), ], ), @@ -93,7 +77,8 @@ class _HttpLogListWidgetState extends State { Color? textColor = LogPoolManager.getInstance().isError(item) ? Colors.red - : Theme.of(context).textTheme.bodyText1!.color; + : Theme.of(context).textTheme.bodyMedium!.color; + return Card( margin: EdgeInsets.all(8), elevation: 6, diff --git a/lib/page/log_request_widget.dart b/lib/page/log_request_widget.dart index 280945d..0aa99be 100644 --- a/lib/page/log_request_widget.dart +++ b/lib/page/log_request_widget.dart @@ -16,7 +16,8 @@ class LogRequestWidget extends StatefulWidget { _LogRequestWidgetState createState() => _LogRequestWidgetState(); } -class _LogRequestWidgetState extends State with AutomaticKeepAliveClientMixin { +class _LogRequestWidgetState extends State + with AutomaticKeepAliveClientMixin { @override Widget build(BuildContext context) { super.build(context);