Tooltip Buttons Updated

This commit is contained in:
Ankit Mahato
2023-04-26 02:53:35 +05:30
parent 1d884cd910
commit 1cbdf2dccc
2 changed files with 67 additions and 46 deletions

View File

@ -5,9 +5,15 @@ import 'package:apidash/consts.dart';
import "snackbars.dart";
class CopyButton extends StatefulWidget {
const CopyButton({super.key, required this.toCopy});
const CopyButton({
super.key,
required this.toCopy,
this.showLabel = true,
});
final String toCopy;
final bool showLabel;
@override
State<CopyButton> createState() => _CopyButtonState();
}
@ -16,21 +22,27 @@ class _CopyButtonState extends State<CopyButton> {
@override
Widget build(BuildContext context) {
var sm = ScaffoldMessenger.of(context);
return TextButton(
onPressed: () async {
await Clipboard.setData(ClipboardData(text: widget.toCopy));
sm.hideCurrentSnackBar();
sm.showSnackBar(getSnackBar("Copied"));
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.content_copy,
size: 20,
return Tooltip(
message: widget.showLabel ? '' : kLabelCopy,
child: SizedBox(
width: widget.showLabel ? null : kTextButtonMinWidth,
child: TextButton(
onPressed: () async {
await Clipboard.setData(ClipboardData(text: widget.toCopy));
sm.hideCurrentSnackBar();
sm.showSnackBar(getSnackBar("Copied"));
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.content_copy,
size: 20,
),
if (widget.showLabel) const Text(kLabelCopy)
],
),
Text(kLabelCopy)
],
),
),
);
}
@ -92,11 +104,13 @@ class SaveInDownloadsButton extends StatefulWidget {
this.content,
this.mimeType,
this.name,
this.showLabel = true,
});
final Uint8List? content;
final String? mimeType;
final String? name;
final bool showLabel;
@override
State<SaveInDownloadsButton> createState() => _SaveInDownloadsButtonState();
@ -106,39 +120,45 @@ class _SaveInDownloadsButtonState extends State<SaveInDownloadsButton> {
@override
Widget build(BuildContext context) {
var sm = ScaffoldMessenger.of(context);
return TextButton(
onPressed: (widget.content != null)
? () async {
var message = "";
var ext = getFileExtension(widget.mimeType);
var path = await getFileDownloadpath(
widget.name,
ext,
);
if (path != null) {
try {
await saveFile(path, widget.content!);
var sp = getShortPath(path);
message = 'Saved to $sp';
} catch (e) {
message = "An error occurred while saving file.";
return Tooltip(
message: widget.showLabel ? '' : kLabelDownload,
child: SizedBox(
width: widget.showLabel ? null : kTextButtonMinWidth,
child: TextButton(
onPressed: (widget.content != null)
? () async {
var message = "";
var ext = getFileExtension(widget.mimeType);
var path = await getFileDownloadpath(
widget.name,
ext,
);
if (path != null) {
try {
await saveFile(path, widget.content!);
var sp = getShortPath(path);
message = 'Saved to $sp';
} catch (e) {
message = "An error occurred while saving file.";
}
} else {
message = "Unable to determine the download path.";
}
sm.hideCurrentSnackBar();
sm.showSnackBar(getSnackBar(message, small: false));
}
} else {
message = "Unable to determine the download path.";
}
sm.hideCurrentSnackBar();
sm.showSnackBar(getSnackBar(message, small: false));
}
: null,
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.download,
size: 20,
: null,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.download,
size: 20,
),
if (widget.showLabel) const Text(kLabelDownload)
],
),
Text(kLabelDownload)
],
),
),
);
}