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

Added quick share action #27

Open
wants to merge 2 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
14 changes: 13 additions & 1 deletion lib/alice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion lib/core/alice_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigatorState> _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() {
Expand Down
20 changes: 12 additions & 8 deletions lib/ui/page/alice_call_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ class _AliceCallDetailsScreenState extends State<AliceCallDetailsScreen>
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(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down