mirror of
https://github.com/foss42/apidash.git
synced 2025-06-28 11:27:06 +08:00
Merge pull request #571 from Mrudul111/main
Implement share button functionality
This commit is contained in:
@ -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";
|
||||
|
@ -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;
|
||||
}
|
||||
|
37
lib/widgets/button_share.dart
Normal file
37
lib/widgets/button_share.dart
Normal file
@ -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));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -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,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
16
pubspec.lock
16
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:
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user