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

Implement share button functionality #571

Merged
merged 16 commits into from
Feb 16, 2025
Merged
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
2 changes: 2 additions & 0 deletions lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ const kLabelSend = "Send";
const kLabelSending = "Sending..";
const kLabelBusy = "Busy";
const kLabelCopy = "Copy";
const kLabelShare = "Share";
const kLabelSave = "Save";
const kLabelDownload = "Download";
const kLabelSaving = "Saving";
Expand Down Expand Up @@ -479,3 +480,4 @@ const kMsgClearHistory =
'Clearing History is permanent. Do you want to continue?';
const kMsgClearHistorySuccess = 'History cleared successfully';
const kMsgClearHistoryError = 'Error clearing history';
const kMsgShareError = "Unable to share";
4 changes: 3 additions & 1 deletion lib/utils/window_utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../consts.dart';

bool showButtonLabelsInBodySuccess(int options, double maxWidth) {
switch (options) {
case 0:
Expand All @@ -14,5 +16,5 @@ bool showButtonLabelsInBodySuccess(int options, double maxWidth) {
}

bool showButtonLabelsInViewCodePane(double maxWidth) {
return (maxWidth < 450) ? false : true;
return (maxWidth < 450 || kIsMobile) ? false : true;
}
37 changes: 37 additions & 0 deletions lib/widgets/button_share.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import '../consts.dart';

class ShareButton extends StatelessWidget {
const ShareButton({
super.key,
required this.toShare,
this.showLabel = true,
});

final String toShare;
final bool showLabel;

@override
Widget build(BuildContext context) {
var sm = ScaffoldMessenger.of(context);

return ADIconButton(
icon: Icons.share,
iconSize: kButtonIconSizeLarge,
tooltip: kLabelShare,
color: Theme.of(context).colorScheme.primary,
visualDensity: VisualDensity.compact,
onPressed: () async {
sm.hideCurrentSnackBar();
try {
await Share.share(toShare);
} catch (e) {
debugPrint("$e");
sm.showSnackBar(getSnackBar(kMsgShareError));
}
},
);
}
}
15 changes: 12 additions & 3 deletions lib/widgets/codegen_previewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
import 'package:highlighter/highlighter.dart' show highlight;
import 'package:apidash/consts.dart';
import 'package:apidash/utils/utils.dart';
import 'button_copy.dart';
import 'button_save_download.dart';
import 'button_share.dart';
import 'code_previewer.dart';
import 'widgets.dart'
show CopyButton, DropdownButtonCodegenLanguage, SaveInDownloadsButton;
import 'dropdown_codegen.dart';

class CodeGenPreviewer extends StatefulWidget {
const CodeGenPreviewer({
Expand Down Expand Up @@ -150,11 +152,18 @@ class ViewCodePane extends StatelessWidget {
toCopy: code,
showLabel: showLabel,
),
Visibility(
visible: kIsMobile,
child: ShareButton(
toShare: code,
showLabel: showLabel,
),
),
SaveInDownloadsButton(
content: stringToBytes(code),
ext: codegenLanguage.ext,
showLabel: showLabel,
)
),
],
),
),
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.0.3"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: fce43200aa03ea87b91ce4c3ac79f0cecd52e2a7a56c7a4185023c271fbfa6da
url: "https://pub.dev"
source: hosted
version: "10.1.4"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: cc012a23fc2d479854e6c80150696c4a5f5bb62cb89af4de1c505cf78d0a5d0b
url: "https://pub.dev"
source: hosted
version: "5.0.2"
shared_preferences:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies:
git:
url: https://github.com/google/flutter-desktop-embedding.git
path: plugins/window_size
share_plus: ^10.1.4

dependency_overrides:
extended_text_field: ^16.0.0
Expand Down