diff --git a/lib/consts.dart b/lib/consts.dart index 92f05c2b..5937636e 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -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"; @@ -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"; diff --git a/lib/utils/window_utils.dart b/lib/utils/window_utils.dart index 32445eb5..6e40a5d0 100644 --- a/lib/utils/window_utils.dart +++ b/lib/utils/window_utils.dart @@ -1,3 +1,5 @@ +import '../consts.dart'; + bool showButtonLabelsInBodySuccess(int options, double maxWidth) { switch (options) { case 0: @@ -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; } diff --git a/lib/widgets/button_share.dart b/lib/widgets/button_share.dart new file mode 100644 index 00000000..bde509fa --- /dev/null +++ b/lib/widgets/button_share.dart @@ -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)); + } + }, + ); + } +} diff --git a/lib/widgets/codegen_previewer.dart b/lib/widgets/codegen_previewer.dart index 5c4aa912..fc498513 100644 --- a/lib/widgets/codegen_previewer.dart +++ b/lib/widgets/codegen_previewer.dart @@ -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({ @@ -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, - ) + ), ], ), ), diff --git a/pubspec.lock b/pubspec.lock index 0f9f35a4..2a8388aa 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index e2d00bad..ce8f9ac4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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