diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aedc2b5..7ad19126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [3.9.1] +- 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 ae84256a..3d12ba4c 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: GestureDetector( + key: Key('quick_share_action_key'), + onLongPress: () => widget.core.quickShareAction?.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( 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: