Tooltip Buttons Updated

This commit is contained in:
Ankit Mahato
2023-04-26 02:53:35 +05:30
parent 1d884cd910
commit 1cbdf2dccc
2 changed files with 67 additions and 46 deletions

View File

@ -61,6 +61,7 @@ const kTabAnimationDuration = Duration(milliseconds: 200);
const kTabHeight = 45.0; const kTabHeight = 45.0;
const kHeaderHeight = 32.0; const kHeaderHeight = 32.0;
const kSegmentHeight = 24.0; const kSegmentHeight = 24.0;
const kTextButtonMinWidth = 36.0;
const kRandMax = 100000; const kRandMax = 100000;

View File

@ -5,9 +5,15 @@ import 'package:apidash/consts.dart';
import "snackbars.dart"; import "snackbars.dart";
class CopyButton extends StatefulWidget { 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 String toCopy;
final bool showLabel;
@override @override
State<CopyButton> createState() => _CopyButtonState(); State<CopyButton> createState() => _CopyButtonState();
} }
@ -16,21 +22,27 @@ class _CopyButtonState extends State<CopyButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var sm = ScaffoldMessenger.of(context); var sm = ScaffoldMessenger.of(context);
return TextButton( return Tooltip(
onPressed: () async { message: widget.showLabel ? '' : kLabelCopy,
await Clipboard.setData(ClipboardData(text: widget.toCopy)); child: SizedBox(
sm.hideCurrentSnackBar(); width: widget.showLabel ? null : kTextButtonMinWidth,
sm.showSnackBar(getSnackBar("Copied")); child: TextButton(
}, onPressed: () async {
child: Row( await Clipboard.setData(ClipboardData(text: widget.toCopy));
mainAxisSize: MainAxisSize.min, sm.hideCurrentSnackBar();
children: const [ sm.showSnackBar(getSnackBar("Copied"));
Icon( },
Icons.content_copy, child: Row(
size: 20, 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.content,
this.mimeType, this.mimeType,
this.name, this.name,
this.showLabel = true,
}); });
final Uint8List? content; final Uint8List? content;
final String? mimeType; final String? mimeType;
final String? name; final String? name;
final bool showLabel;
@override @override
State<SaveInDownloadsButton> createState() => _SaveInDownloadsButtonState(); State<SaveInDownloadsButton> createState() => _SaveInDownloadsButtonState();
@ -106,39 +120,45 @@ class _SaveInDownloadsButtonState extends State<SaveInDownloadsButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var sm = ScaffoldMessenger.of(context); var sm = ScaffoldMessenger.of(context);
return TextButton( return Tooltip(
onPressed: (widget.content != null) message: widget.showLabel ? '' : kLabelDownload,
? () async { child: SizedBox(
var message = ""; width: widget.showLabel ? null : kTextButtonMinWidth,
var ext = getFileExtension(widget.mimeType); child: TextButton(
var path = await getFileDownloadpath( onPressed: (widget.content != null)
widget.name, ? () async {
ext, var message = "";
); var ext = getFileExtension(widget.mimeType);
if (path != null) { var path = await getFileDownloadpath(
try { widget.name,
await saveFile(path, widget.content!); ext,
var sp = getShortPath(path); );
message = 'Saved to $sp'; if (path != null) {
} catch (e) { try {
message = "An error occurred while saving file."; 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 { : null,
message = "Unable to determine the download path."; child: Row(
} mainAxisSize: MainAxisSize.min,
sm.hideCurrentSnackBar(); children: [
sm.showSnackBar(getSnackBar(message, small: false)); const Icon(
} Icons.download,
: null, size: 20,
child: Row( ),
mainAxisSize: MainAxisSize.min, if (widget.showLabel) const Text(kLabelDownload)
children: const [ ],
Icon(
Icons.download,
size: 20,
), ),
Text(kLabelDownload) ),
],
), ),
); );
} }