Skip to content

Add share feature for dio request/response #123

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

Open
wants to merge 3 commits into
base: master
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
205 changes: 205 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "flutter_ume",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "custom_plugin_example",
"cwd": "custom_plugin_example",
"request": "launch",
"type": "dart"
},
{
"name": "custom_plugin_example (profile mode)",
"cwd": "custom_plugin_example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "custom_plugin_example (release mode)",
"cwd": "custom_plugin_example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_ume_kit_channel_monitor",
"cwd": "kits/flutter_ume_kit_channel_monitor",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume_kit_channel_monitor (profile mode)",
"cwd": "kits/flutter_ume_kit_channel_monitor",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume_kit_channel_monitor (release mode)",
"cwd": "kits/flutter_ume_kit_channel_monitor",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_ume_kit_console",
"cwd": "kits/flutter_ume_kit_console",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume_kit_console (profile mode)",
"cwd": "kits/flutter_ume_kit_console",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume_kit_console (release mode)",
"cwd": "kits/flutter_ume_kit_console",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_ume_kit_device",
"cwd": "kits/flutter_ume_kit_device",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume_kit_device (profile mode)",
"cwd": "kits/flutter_ume_kit_device",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume_kit_device (release mode)",
"cwd": "kits/flutter_ume_kit_device",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_ume_kit_dio",
"cwd": "kits/flutter_ume_kit_dio",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume_kit_dio (profile mode)",
"cwd": "kits/flutter_ume_kit_dio",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume_kit_dio (release mode)",
"cwd": "kits/flutter_ume_kit_dio",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_ume_kit_perf",
"cwd": "kits/flutter_ume_kit_perf",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume_kit_perf (profile mode)",
"cwd": "kits/flutter_ume_kit_perf",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume_kit_perf (release mode)",
"cwd": "kits/flutter_ume_kit_perf",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_ume_kit_show_code",
"cwd": "kits/flutter_ume_kit_show_code",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume_kit_show_code (profile mode)",
"cwd": "kits/flutter_ume_kit_show_code",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume_kit_show_code (release mode)",
"cwd": "kits/flutter_ume_kit_show_code",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_ume_kit_ui",
"cwd": "kits/flutter_ume_kit_ui",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_ume_kit_ui (profile mode)",
"cwd": "kits/flutter_ume_kit_ui",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_ume_kit_ui (release mode)",
"cwd": "kits/flutter_ume_kit_ui",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
2 changes: 1 addition & 1 deletion example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _HomePageState extends State<HomePage> {
(int i) => Future<void>.delayed(
Duration(seconds: i),
() => dio.get(
'https://api.github.com'
'https://apis.github.com'
'/?_t=${DateTime.now().millisecondsSinceEpoch}&$i',
options: Options(
headers: {'UME-Test': 'This is UME Dio kit.'},
Expand Down
13 changes: 7 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import 'package:example/ume_switch.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ume/flutter_ume.dart';
import 'package:flutter_ume_kit_ui/flutter_ume_kit_ui.dart';
import 'package:flutter_ume_kit_channel_monitor/flutter_ume_kit_channel_monitor.dart';
import 'package:flutter_ume_kit_console/flutter_ume_kit_console.dart';
import 'package:flutter_ume_kit_device/flutter_ume_kit_device.dart';
import 'package:flutter_ume_kit_dio/flutter_ume_kit_dio.dart';
import 'package:flutter_ume_kit_perf/flutter_ume_kit_perf.dart';
import 'package:flutter_ume_kit_show_code/flutter_ume_kit_show_code.dart';
import 'package:flutter_ume_kit_device/flutter_ume_kit_device.dart';
import 'package:flutter_ume_kit_console/flutter_ume_kit_console.dart';
import 'package:flutter_ume_kit_ui/flutter_ume_kit_ui.dart';
import 'package:provider/provider.dart';
import 'package:flutter_ume_kit_dio/flutter_ume_kit_dio.dart';
import 'package:flutter_ume_kit_channel_monitor/flutter_ume_kit_channel_monitor.dart';

final Dio dio = Dio()..options = BaseOptions(connectTimeout: 10000);
final Dio dio = Dio()
..options = BaseOptions(connectTimeout: Duration(milliseconds: 10000));

final navigatorKey = GlobalKey<NavigatorState>();

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
sdk: flutter
provider: ^6.0.3
# For Dio Kit
dio: ^4.0.0
dio: ^5.1.2

dependency_overrides:
vm_service: ^9.4.0
Expand Down
5 changes: 3 additions & 2 deletions kits/flutter_ume_kit_dio/lib/src/models/http_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class UMEDioInterceptor extends Interceptor {
@override
void onError(DioError err, ErrorInterceptorHandler handler) {
// Create an empty response with the [RequestOptions] for delivery.
err.response ??= Response<dynamic>(requestOptions: err.requestOptions);
err.response!.requestOptions.extra[DIO_EXTRA_END_TIME] = _timestamp;
var errRespon = Response<dynamic>(requestOptions: err.requestOptions);
// err.response ??= Response<dynamic>(requestOptions: err.requestOptions);
errRespon.requestOptions.extra[DIO_EXTRA_END_TIME] = _timestamp;
InspectorInstance.httpContainer.addRequest(err.response!);
handler.next(err);
}
Expand Down
40 changes: 36 additions & 4 deletions kits/flutter_ume_kit_dio/lib/src/widgets/pluggable_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
///
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';

import '../constants/extensions.dart';
import '../instances.dart';
Expand All @@ -18,13 +19,13 @@ ButtonStyle _buttonStyle(
EdgeInsetsGeometry? padding,
}) {
return TextButton.styleFrom(
foregroundColor: Colors.white,
padding: padding ?? const EdgeInsets.symmetric(horizontal: 5, vertical: 3),
minimumSize: Size.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(999999),
),
backgroundColor: Theme.of(context).primaryColor,
primary: Colors.white,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
}
Expand Down Expand Up @@ -116,7 +117,7 @@ class DioPluggableState extends State<DioInspector> {
return Material(
color: Colors.black26,
child: DefaultTextStyle.merge(
style: Theme.of(context).textTheme.bodyText2,
style: Theme.of(context).textTheme.bodyMedium,
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
Expand All @@ -139,7 +140,7 @@ class DioPluggableState extends State<DioInspector> {
const Spacer(),
Text(
'Dio Requests',
style: Theme.of(context).textTheme.subtitle1,
style: Theme.of(context).textTheme.titleMedium,
),
Expanded(
child: Align(
Expand Down Expand Up @@ -308,11 +309,42 @@ class _ResponseCardState extends State<_ResponseCard> {
const SizedBox(width: 6),
Text('${_duration.inMilliseconds}ms'),
const Spacer(),
_shareButton(context),
const SizedBox(width: 6),
_detailButton(context),
],
);
}

Widget _shareButton(BuildContext context) {
return TextButton(
onPressed: () {
Share.share(_buildShareContent());
},
style: _buttonStyle(context),
child: const Text(
'Share↗',
style: TextStyle(fontSize: 12, height: 1.2),
),
);
}

_buildShareContent() {
return "URL: $_requestUri\n" +
"**************\n" +
"Request headers\n" +
"$_requestHeadersBuilder\n" +
"**************\n" +
"Request Data\n" +
"$_requestDataBuilder\n" +
"**************\n" +
"Response body\n" +
"$_responseDataBuilder\n" +
"**************\n" +
"Response headers\n" +
"$_responseHeadersBuilder\n";
}

Widget _detailedContent(BuildContext context) {
return ValueListenableBuilder<bool>(
valueListenable: _isExpanded,
Expand Down
5 changes: 4 additions & 1 deletion kits/flutter_ume_kit_dio/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ dependencies:
sdk: flutter
flutter_ume: ">=1.0.0 <2.0.0"

dio: ^4.0.0
dio: ^5.1.2

share_plus: ^4.5.3


dev_dependencies:
flutter_test:
Expand Down