mirror of
https://github.com/foss42/apidash.git
synced 2025-06-05 10:20:44 +08:00
Tooltip Buttons Updated
This commit is contained in:
@ -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)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user