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(
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 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,
);
} }
} }

View File

@ -23,45 +23,46 @@ 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(
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 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,
);
} }
} }

View File

@ -176,35 +176,77 @@ class _JsonPreviewerState extends State<JsonPreviewer> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: constraints.minWidth > kMinWindowSize.width
TextButton( ? [
onPressed: () async { TextButton(
await _copy(kEncoder.convert(widget.code), sm); onPressed: () async {
}, await _copy(
child: const Text( kEncoder.convert(widget.code), sm);
'Copy', },
style: kTextStyleButtonSmall, child: const Text(
), 'Copy',
), style: kTextStyleButtonSmall,
TextButton( ),
onPressed: ),
state.areAllExpanded() ? null : state.expandAll, TextButton(
child: const Text( onPressed: state.areAllExpanded()
'Expand All', ? null
style: kTextStyleButtonSmall, : state.expandAll,
), child: const Text(
), 'Expand All',
TextButton( style: kTextStyleButtonSmall,
onPressed: ),
state.areAllCollapsed() ? null : state.collapseAll, ),
child: const Text( TextButton(
'Collapse All', onPressed: state.areAllCollapsed()
style: kTextStyleButtonSmall, ? 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( 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(),