diff --git a/lib/widgets/button_copy.dart b/lib/widgets/button_copy.dart index 8c3d56de..ec6e7f36 100644 --- a/lib/widgets/button_copy.dart +++ b/lib/widgets/button_copy.dart @@ -16,28 +16,29 @@ class CopyButton extends StatelessWidget { @override Widget build(BuildContext context) { var sm = ScaffoldMessenger.of(context); - return Tooltip( - message: showLabel ? '' : kLabelCopy, - child: SizedBox( - width: showLabel ? null : kTextButtonMinWidth, - child: TextButton( - onPressed: () async { - await Clipboard.setData(ClipboardData(text: toCopy)); - sm.hideCurrentSnackBar(); - sm.showSnackBar(getSnackBar("Copied")); - }, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon( - Icons.content_copy, - size: 20, - ), - if (showLabel) const Text(kLabelCopy) - ], - ), - ), - ), + const icon = Icon( + Icons.content_copy, + size: 18, ); + const label = kLabelCopy; + onPressed() async { + await Clipboard.setData(ClipboardData(text: toCopy)); + sm.hideCurrentSnackBar(); + sm.showSnackBar(getSnackBar("Copied")); + } + + return showLabel + ? TextButton.icon( + onPressed: onPressed, + icon: icon, + label: const Text(label), + ) + : IconButton( + tooltip: label, + color: Theme.of(context).colorScheme.primary, + visualDensity: VisualDensity.compact, + onPressed: onPressed, + icon: icon, + ); } } diff --git a/lib/widgets/button_save_download.dart b/lib/widgets/button_save_download.dart index b3ffbb31..c329869c 100644 --- a/lib/widgets/button_save_download.dart +++ b/lib/widgets/button_save_download.dart @@ -23,45 +23,46 @@ class SaveInDownloadsButton extends StatelessWidget { @override Widget build(BuildContext context) { var sm = ScaffoldMessenger.of(context); - return Tooltip( - message: showLabel ? '' : kLabelDownload, - child: SizedBox( - width: showLabel ? null : kTextButtonMinWidth, - child: TextButton( - onPressed: (content != null) - ? () async { - var message = ""; - var path = await getFileDownloadpath( - name, - ext ?? getFileExtension(mimeType), - ); - if (path != null) { - try { - await saveFile(path, 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)); - } - : null, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon( - Icons.download, - size: 20, - ), - if (showLabel) const Text(kLabelDownload) - ], - ), - ), - ), + const icon = Icon( + Icons.download, + size: 18, ); + const label = kLabelDownload; + final onPressed = (content != null) + ? () async { + var message = ""; + var path = await getFileDownloadpath( + name, + ext ?? getFileExtension(mimeType), + ); + if (path != null) { + try { + await saveFile(path, 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)); + } + : null; + + return showLabel + ? TextButton.icon( + onPressed: onPressed, + icon: icon, + label: const Text(label), + ) + : IconButton( + tooltip: label, + color: Theme.of(context).colorScheme.primary, + visualDensity: VisualDensity.compact, + onPressed: onPressed, + icon: icon, + ); } } diff --git a/lib/widgets/json_previewer.dart b/lib/widgets/json_previewer.dart index 088c6026..3a4f5648 100644 --- a/lib/widgets/json_previewer.dart +++ b/lib/widgets/json_previewer.dart @@ -176,35 +176,77 @@ class _JsonPreviewerState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: () async { - await _copy(kEncoder.convert(widget.code), sm); - }, - child: const Text( - 'Copy', - style: kTextStyleButtonSmall, - ), - ), - TextButton( - onPressed: - state.areAllExpanded() ? null : state.expandAll, - child: const Text( - 'Expand All', - style: kTextStyleButtonSmall, - ), - ), - TextButton( - onPressed: - state.areAllCollapsed() ? null : state.collapseAll, - child: const Text( - 'Collapse All', - style: kTextStyleButtonSmall, - ), - ), - ], - ), + mainAxisAlignment: MainAxisAlignment.end, + children: constraints.minWidth > kMinWindowSize.width + ? [ + TextButton( + onPressed: () async { + await _copy( + kEncoder.convert(widget.code), sm); + }, + child: const Text( + 'Copy', + style: kTextStyleButtonSmall, + ), + ), + TextButton( + onPressed: state.areAllExpanded() + ? null + : state.expandAll, + child: const Text( + 'Expand All', + style: kTextStyleButtonSmall, + ), + ), + TextButton( + onPressed: state.areAllCollapsed() + ? null + : state.collapseAll, + child: const Text( + 'Collapse All', + style: kTextStyleButtonSmall, + ), + ), + ] + : [ + IconButton( + tooltip: "Copy", + color: Theme.of(context).colorScheme.primary, + visualDensity: VisualDensity.compact, + onPressed: () async { + await _copy( + kEncoder.convert(widget.code), sm); + }, + icon: const Icon( + Icons.copy, + size: 16, + ), + ), + IconButton( + tooltip: "Expand All", + color: Theme.of(context).colorScheme.primary, + visualDensity: VisualDensity.compact, + onPressed: state.areAllExpanded() + ? null + : state.expandAll, + icon: const Icon( + Icons.unfold_more, + size: 16, + ), + ), + IconButton( + tooltip: "Collapse All", + color: Theme.of(context).colorScheme.primary, + visualDensity: VisualDensity.compact, + onPressed: state.areAllCollapsed() + ? null + : state.collapseAll, + icon: const Icon( + Icons.unfold_less, + size: 16, + ), + ), + ]), Expanded( child: JsonDataExplorer( nodes: state.displayNodes, diff --git a/lib/widgets/response_widgets.dart b/lib/widgets/response_widgets.dart index 0d3bd7a7..54a93db9 100644 --- a/lib/widgets/response_widgets.dart +++ b/lib/widgets/response_widgets.dart @@ -425,6 +425,7 @@ class _BodySuccessState extends State { (widget.options == kRawBodyViewOptions) ? const SizedBox() : SegmentedButton( + showSelectedIcon: showLabel, style: const ButtonStyle( padding: WidgetStatePropertyAll( EdgeInsets.symmetric( @@ -438,7 +439,7 @@ class _BodySuccessState extends State { (e) => ButtonSegment( value: e, label: Text(e.label), - icon: Icon(e.icon), + icon: showLabel ? Icon(e.icon) : null, ), ) .toList(),