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,7 +22,11 @@ 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(
message: widget.showLabel ? '' : kLabelCopy,
child: SizedBox(
width: widget.showLabel ? null : kTextButtonMinWidth,
child: TextButton(
onPressed: () async { onPressed: () async {
await Clipboard.setData(ClipboardData(text: widget.toCopy)); await Clipboard.setData(ClipboardData(text: widget.toCopy));
sm.hideCurrentSnackBar(); sm.hideCurrentSnackBar();
@ -24,14 +34,16 @@ class _CopyButtonState extends State<CopyButton> {
}, },
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: const [ children: [
Icon( const Icon(
Icons.content_copy, Icons.content_copy,
size: 20, size: 20,
), ),
Text(kLabelCopy) if (widget.showLabel) const 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,7 +120,11 @@ 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(
message: widget.showLabel ? '' : kLabelDownload,
child: SizedBox(
width: widget.showLabel ? null : kTextButtonMinWidth,
child: TextButton(
onPressed: (widget.content != null) onPressed: (widget.content != null)
? () async { ? () async {
var message = ""; var message = "";
@ -132,14 +150,16 @@ class _SaveInDownloadsButtonState extends State<SaveInDownloadsButton> {
: null, : null,
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: const [ children: [
Icon( const Icon(
Icons.download, Icons.download,
size: 20, size: 20,
), ),
Text(kLabelDownload) if (widget.showLabel) const Text(kLabelDownload)
], ],
), ),
),
),
); );
} }
} }