fix: render overflow errors

This commit is contained in:
DenserMeerkat
2024-07-04 16:10:51 +05:30
parent 063638b8ef
commit 8ee7bc843b
4 changed files with 136 additions and 91 deletions

View File

@ -16,28 +16,29 @@ class CopyButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var sm = ScaffoldMessenger.of(context); var sm = ScaffoldMessenger.of(context);
return Tooltip( const icon = Icon(
message: showLabel ? '' : kLabelCopy, Icons.content_copy,
child: SizedBox( size: 18,
width: showLabel ? null : kTextButtonMinWidth, );
child: TextButton( const label = kLabelCopy;
onPressed: () async { onPressed() async {
await Clipboard.setData(ClipboardData(text: toCopy)); await Clipboard.setData(ClipboardData(text: toCopy));
sm.hideCurrentSnackBar(); sm.hideCurrentSnackBar();
sm.showSnackBar(getSnackBar("Copied")); sm.showSnackBar(getSnackBar("Copied"));
}, }
child: Row(
mainAxisSize: MainAxisSize.min, return showLabel
children: [ ? TextButton.icon(
const Icon( onPressed: onPressed,
Icons.content_copy, icon: icon,
size: 20, label: const Text(label),
), )
if (showLabel) const Text(kLabelCopy) : IconButton(
], tooltip: label,
), color: Theme.of(context).colorScheme.primary,
), visualDensity: VisualDensity.compact,
), onPressed: onPressed,
icon: icon,
); );
} }
} }

View File

@ -23,12 +23,12 @@ class SaveInDownloadsButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var sm = ScaffoldMessenger.of(context); var sm = ScaffoldMessenger.of(context);
return Tooltip( const icon = Icon(
message: showLabel ? '' : kLabelDownload, Icons.download,
child: SizedBox( size: 18,
width: showLabel ? null : kTextButtonMinWidth, );
child: TextButton( const label = kLabelDownload;
onPressed: (content != null) final onPressed = (content != null)
? () async { ? () async {
var message = ""; var message = "";
var path = await getFileDownloadpath( var path = await getFileDownloadpath(
@ -49,19 +49,20 @@ class SaveInDownloadsButton extends StatelessWidget {
sm.hideCurrentSnackBar(); sm.hideCurrentSnackBar();
sm.showSnackBar(getSnackBar(message, small: false)); sm.showSnackBar(getSnackBar(message, small: false));
} }
: null, : null;
child: Row(
mainAxisSize: MainAxisSize.min, return showLabel
children: [ ? TextButton.icon(
const Icon( onPressed: onPressed,
Icons.download, icon: icon,
size: 20, label: const Text(label),
), )
if (showLabel) const Text(kLabelDownload) : IconButton(
], tooltip: label,
), color: Theme.of(context).colorScheme.primary,
), visualDensity: VisualDensity.compact,
), onPressed: onPressed,
icon: icon,
); );
} }
} }

View File

@ -177,10 +177,12 @@ class _JsonPreviewerState extends State<JsonPreviewer> {
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: constraints.minWidth > kMinWindowSize.width
? [
TextButton( TextButton(
onPressed: () async { onPressed: () async {
await _copy(kEncoder.convert(widget.code), sm); await _copy(
kEncoder.convert(widget.code), sm);
}, },
child: const Text( child: const Text(
'Copy', 'Copy',
@ -188,23 +190,63 @@ class _JsonPreviewerState extends State<JsonPreviewer> {
), ),
), ),
TextButton( TextButton(
onPressed: onPressed: state.areAllExpanded()
state.areAllExpanded() ? null : state.expandAll, ? null
: state.expandAll,
child: const Text( child: const Text(
'Expand All', 'Expand All',
style: kTextStyleButtonSmall, style: kTextStyleButtonSmall,
), ),
), ),
TextButton( TextButton(
onPressed: onPressed: state.areAllCollapsed()
state.areAllCollapsed() ? null : state.collapseAll, ? null
: state.collapseAll,
child: const Text( child: const Text(
'Collapse All', 'Collapse All',
style: kTextStyleButtonSmall, 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( Expanded(
child: JsonDataExplorer( child: JsonDataExplorer(
nodes: state.displayNodes, nodes: state.displayNodes,

View File

@ -425,6 +425,7 @@ class _BodySuccessState extends State<BodySuccess> {
(widget.options == kRawBodyViewOptions) (widget.options == kRawBodyViewOptions)
? const SizedBox() ? const SizedBox()
: SegmentedButton<ResponseBodyView>( : SegmentedButton<ResponseBodyView>(
showSelectedIcon: showLabel,
style: const ButtonStyle( style: const ButtonStyle(
padding: WidgetStatePropertyAll( padding: WidgetStatePropertyAll(
EdgeInsets.symmetric( EdgeInsets.symmetric(
@ -438,7 +439,7 @@ class _BodySuccessState extends State<BodySuccess> {
(e) => ButtonSegment<ResponseBodyView>( (e) => ButtonSegment<ResponseBodyView>(
value: e, value: e,
label: Text(e.label), label: Text(e.label),
icon: Icon(e.icon), icon: showLabel ? Icon(e.icon) : null,
), ),
) )
.toList(), .toList(),