Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dio version, add copy cURL function #20

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dart_tool/version

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ workspace.xml
.dart_tool
.fvm
.vscode
.DS_Store
.dart_tool
2 changes: 2 additions & 0 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sdk.dir=/Users/pingyangliao/Library/Android/sdk
flutter.sdk=/Users/pingyangliao/SDK/flutter
5 changes: 3 additions & 2 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,6 +26,7 @@ class _MyHomePageState extends State<MyHomePage> {

@override
void dispose() {
controller.dispose();
super.dispose();
}

Expand All @@ -40,7 +41,7 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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,
Expand Down
11 changes: 10 additions & 1 deletion example/lib/http_utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:dio_log/dio_log.dart';

Expand All @@ -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'},
),
);
}
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/bean/req_options.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

///需要的请求数据类
class ReqOptions {
int? id;
Expand All @@ -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(' ');
}
}
33 changes: 9 additions & 24 deletions lib/http_log_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,25 @@ class _HttpLogListWidgetState extends State<HttpLogListWidget> {
elevation: 1.0,
iconTheme: theme.iconTheme,
actions: <Widget>[
InkWell(
onTap: () {
FilledButton(
onPressed: () {
if (debugBtnIsShow()) {
dismissDebugBtn();
} else {
showDebugBtn(context);
}
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'),
),
],
),
Expand Down Expand Up @@ -93,7 +77,8 @@ class _HttpLogListWidgetState extends State<HttpLogListWidget> {

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,
Expand Down
6 changes: 4 additions & 2 deletions lib/overlay_draggable_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

///关闭悬浮按钮
Expand Down
55 changes: 22 additions & 33 deletions lib/page/log_request_widget.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,29 +18,6 @@ class LogRequestWidget extends StatefulWidget {

class _LogRequestWidgetState extends State<LogRequestWidget>
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();
}

@override
Widget build(BuildContext context) {
super.build(context);
Expand All @@ -61,15 +39,26 @@ class _LogRequestWidgetState extends State<LogRequestWidget>
'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),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
dependencies:
flutter:
sdk: flutter
dio: ^4.0.0
dio: ^5.0.0

dev_dependencies:
flutter_test:
Expand Down