Skip to content

Commit d6ea9f3

Browse files
authored
Merge pull request #571 from Mrudul111/main
Implement share button functionality
2 parents 9025435 + 23c6914 commit d6ea9f3

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

lib/consts.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ const kLabelSend = "Send";
421421
const kLabelSending = "Sending..";
422422
const kLabelBusy = "Busy";
423423
const kLabelCopy = "Copy";
424+
const kLabelShare = "Share";
424425
const kLabelSave = "Save";
425426
const kLabelDownload = "Download";
426427
const kLabelSaving = "Saving";
@@ -479,3 +480,4 @@ const kMsgClearHistory =
479480
'Clearing History is permanent. Do you want to continue?';
480481
const kMsgClearHistorySuccess = 'History cleared successfully';
481482
const kMsgClearHistoryError = 'Error clearing history';
483+
const kMsgShareError = "Unable to share";

lib/utils/window_utils.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '../consts.dart';
2+
13
bool showButtonLabelsInBodySuccess(int options, double maxWidth) {
24
switch (options) {
35
case 0:
@@ -14,5 +16,5 @@ bool showButtonLabelsInBodySuccess(int options, double maxWidth) {
1416
}
1517

1618
bool showButtonLabelsInViewCodePane(double maxWidth) {
17-
return (maxWidth < 450) ? false : true;
19+
return (maxWidth < 450 || kIsMobile) ? false : true;
1820
}

lib/widgets/button_share.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:apidash_design_system/apidash_design_system.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:share_plus/share_plus.dart';
4+
import '../consts.dart';
5+
6+
class ShareButton extends StatelessWidget {
7+
const ShareButton({
8+
super.key,
9+
required this.toShare,
10+
this.showLabel = true,
11+
});
12+
13+
final String toShare;
14+
final bool showLabel;
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
var sm = ScaffoldMessenger.of(context);
19+
20+
return ADIconButton(
21+
icon: Icons.share,
22+
iconSize: kButtonIconSizeLarge,
23+
tooltip: kLabelShare,
24+
color: Theme.of(context).colorScheme.primary,
25+
visualDensity: VisualDensity.compact,
26+
onPressed: () async {
27+
sm.hideCurrentSnackBar();
28+
try {
29+
await Share.share(toShare);
30+
} catch (e) {
31+
debugPrint("$e");
32+
sm.showSnackBar(getSnackBar(kMsgShareError));
33+
}
34+
},
35+
);
36+
}
37+
}

lib/widgets/codegen_previewer.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
33
import 'package:highlighter/highlighter.dart' show highlight;
44
import 'package:apidash/consts.dart';
55
import 'package:apidash/utils/utils.dart';
6+
import 'button_copy.dart';
7+
import 'button_save_download.dart';
8+
import 'button_share.dart';
69
import 'code_previewer.dart';
7-
import 'widgets.dart'
8-
show CopyButton, DropdownButtonCodegenLanguage, SaveInDownloadsButton;
10+
import 'dropdown_codegen.dart';
911

1012
class CodeGenPreviewer extends StatefulWidget {
1113
const CodeGenPreviewer({
@@ -150,11 +152,18 @@ class ViewCodePane extends StatelessWidget {
150152
toCopy: code,
151153
showLabel: showLabel,
152154
),
155+
Visibility(
156+
visible: kIsMobile,
157+
child: ShareButton(
158+
toShare: code,
159+
showLabel: showLabel,
160+
),
161+
),
153162
SaveInDownloadsButton(
154163
content: stringToBytes(code),
155164
ext: codegenLanguage.ext,
156165
showLabel: showLabel,
157-
)
166+
),
158167
],
159168
),
160169
),

pubspec.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,22 @@ packages:
13681368
url: "https://pub.dev"
13691369
source: hosted
13701370
version: "0.0.3"
1371+
share_plus:
1372+
dependency: "direct main"
1373+
description:
1374+
name: share_plus
1375+
sha256: fce43200aa03ea87b91ce4c3ac79f0cecd52e2a7a56c7a4185023c271fbfa6da
1376+
url: "https://pub.dev"
1377+
source: hosted
1378+
version: "10.1.4"
1379+
share_plus_platform_interface:
1380+
dependency: transitive
1381+
description:
1382+
name: share_plus_platform_interface
1383+
sha256: cc012a23fc2d479854e6c80150696c4a5f5bb62cb89af4de1c505cf78d0a5d0b
1384+
url: "https://pub.dev"
1385+
source: hosted
1386+
version: "5.0.2"
13711387
shared_preferences:
13721388
dependency: "direct main"
13731389
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ dependencies:
6767
git:
6868
url: https://github.com/google/flutter-desktop-embedding.git
6969
path: plugins/window_size
70+
share_plus: ^10.1.4
7071

7172
dependency_overrides:
7273
extended_text_field: ^16.0.0

0 commit comments

Comments
 (0)