From fba8d8f4857d6a4f0f54de3ba6e69ed070d458f7 Mon Sep 17 00:00:00 2001 From: Nikolay Kirillov Date: Fri, 22 Nov 2024 22:29:33 +0300 Subject: [PATCH 1/2] Long press share button to share cURL command --- CHANGELOG.md | 3 ++ lib/ui/page/alice_call_details_screen.dart | 41 +++++++++++++++++----- pubspec.yaml | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aedc2b5..c236a541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [3.9.1] +- Long press share button to share cURL command + ## [3.9.0] - Bump dependencies diff --git a/lib/ui/page/alice_call_details_screen.dart b/lib/ui/page/alice_call_details_screen.dart index ae84256a..f34a18f6 100644 --- a/lib/ui/page/alice_call_details_screen.dart +++ b/lib/ui/page/alice_call_details_screen.dart @@ -69,14 +69,18 @@ class _AliceCallDetailsScreenState extends State return DefaultTabController( length: 4, child: Scaffold( - floatingActionButton: FloatingActionButton( - backgroundColor: AliceConstants.lightRed(widget.customColors), - key: Key('share_key'), - onPressed: () async { - Share.share(await _getSharableResponseString(), - subject: 'Request Details'); - }, - child: Icon(Icons.share, color: Colors.white), + floatingActionButton: _LongPressHandler( + key: Key('long_press_handler_key'), + call: call, + child: FloatingActionButton( + backgroundColor: AliceConstants.lightRed(widget.customColors), + key: Key('share_key'), + onPressed: () async { + Share.share(await _getSharableResponseString(), + subject: 'Request Details'); + }, + child: Icon(Icons.share, color: Colors.white), + ), ), appBar: AppBar( bottom: TabBar( @@ -123,3 +127,24 @@ class _AliceCallDetailsScreenState extends State return widgets; } } + +class _LongPressHandler extends StatelessWidget { + const _LongPressHandler({ + required this.child, + required this.call, + super.key, + }); + final AliceHttpCall call; + final Widget child; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onLongPress: () => Share.share( + call.getCurlCommand(), + subject: 'cURL Command', + ), + child: child, + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index e6a003d7..b50f4a13 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: alice_lightweight description: Lightweight Alice version. Removed additional dependencies except dio. -version: 3.9.0 +version: 3.9.1 homepage: https://github.com/jhomlala/alice environment: From c2f9ccd6e254b87accedabccc1db89dad897dce9 Mon Sep 17 00:00:00 2001 From: Nikolay Kirillov Date: Sat, 23 Nov 2024 17:28:40 +0300 Subject: [PATCH 2/2] added quickShareAction --- CHANGELOG.md | 2 +- lib/alice.dart | 14 ++++++++++- lib/core/alice_core.dart | 8 ++++++- lib/ui/page/alice_call_details_screen.dart | 27 +++------------------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c236a541..7ad19126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## [3.9.1] -- Long press share button to share cURL command +- Added `quickShareAction` property. This action will be called on long press on share button. It has AliceHttpCall as argument and should be used to handle share action. By default it will share cURL command. ## [3.9.0] - Bump dependencies diff --git a/lib/alice.dart b/lib/alice.dart index 1e9831b4..fc49dec2 100644 --- a/lib/alice.dart +++ b/lib/alice.dart @@ -9,6 +9,7 @@ import 'package:alice_lightweight/model/alice_http_call.dart'; import 'package:alice_lightweight/utils/alice_custom_colors.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:share_plus/share_plus.dart'; export 'package:alice_lightweight/utils/alice_custom_colors.dart'; @@ -43,8 +44,19 @@ class Alice { ) bool darkTheme = false, AliceCustomColors customColors = const AliceCustomColors(), + void Function(AliceHttpCall aliceHttpCall)? quickShareAction, }) { - final aliceCore = AliceCore(navigatorKey, customColors); + final defaultQuickShareAction = (call) { + Share.share( + call.getCurlCommand(), + subject: 'cURL Command', + ); + }; + final aliceCore = AliceCore( + navigatorKey, + customColors, + quickShareAction ?? defaultQuickShareAction, + ); final httpClientAdapter = AliceHttpClientAdapter(aliceCore); final httpAdapter = AliceHttpAdapter(aliceCore); diff --git a/lib/core/alice_core.dart b/lib/core/alice_core.dart index fc9fb186..3abb810e 100644 --- a/lib/core/alice_core.dart +++ b/lib/core/alice_core.dart @@ -14,12 +14,18 @@ class AliceCore { BehaviorSubject.seeded([]); final AliceCustomColors customColors; + /// Function which will be called on long press on share button. + /// It has AliceHttpCall as argument and should be used to handle share action. + /// + /// By default it will share cURL command. + final void Function(AliceHttpCall aliceHttpCall)? quickShareAction; + GlobalKey _navigatorKey; bool _isInspectorOpened = false; StreamSubscription? _callsSubscription; /// Creates alice core instance - AliceCore(this._navigatorKey, this.customColors); + AliceCore(this._navigatorKey, this.customColors, [this.quickShareAction]); /// Dispose subjects and subscriptions void dispose() { diff --git a/lib/ui/page/alice_call_details_screen.dart b/lib/ui/page/alice_call_details_screen.dart index f34a18f6..3d12ba4c 100644 --- a/lib/ui/page/alice_call_details_screen.dart +++ b/lib/ui/page/alice_call_details_screen.dart @@ -69,9 +69,9 @@ class _AliceCallDetailsScreenState extends State return DefaultTabController( length: 4, child: Scaffold( - floatingActionButton: _LongPressHandler( - key: Key('long_press_handler_key'), - call: call, + floatingActionButton: GestureDetector( + key: Key('quick_share_action_key'), + onLongPress: () => widget.core.quickShareAction?.call(call), child: FloatingActionButton( backgroundColor: AliceConstants.lightRed(widget.customColors), key: Key('share_key'), @@ -127,24 +127,3 @@ class _AliceCallDetailsScreenState extends State return widgets; } } - -class _LongPressHandler extends StatelessWidget { - const _LongPressHandler({ - required this.child, - required this.call, - super.key, - }); - final AliceHttpCall call; - final Widget child; - - @override - Widget build(BuildContext context) { - return GestureDetector( - onLongPress: () => Share.share( - call.getCurlCommand(), - subject: 'cURL Command', - ), - child: child, - ); - } -}