diff --git a/lib/consts.dart b/lib/consts.dart index b4926b72..707809bb 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -61,6 +61,7 @@ const kTabAnimationDuration = Duration(milliseconds: 200); const kTabHeight = 45.0; const kHeaderHeight = 32.0; const kSegmentHeight = 24.0; +const kTextButtonMinWidth = 36.0; const kRandMax = 100000; diff --git a/lib/widgets/buttons.dart b/lib/widgets/buttons.dart index 59ef2958..257b57e8 100644 --- a/lib/widgets/buttons.dart +++ b/lib/widgets/buttons.dart @@ -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 createState() => _CopyButtonState(); } @@ -16,21 +22,27 @@ class _CopyButtonState extends State { @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 createState() => _SaveInDownloadsButtonState(); @@ -106,39 +120,45 @@ class _SaveInDownloadsButtonState extends State { @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) - ], + ), ), ); }