mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 13:51:20 +08:00
Migrate to ADFilledButton & ADTextButton
This commit is contained in:
@ -16,10 +16,6 @@ class CopyButton extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var sm = ScaffoldMessenger.of(context);
|
var sm = ScaffoldMessenger.of(context);
|
||||||
const icon = Icon(
|
|
||||||
Icons.content_copy,
|
|
||||||
size: 18,
|
|
||||||
);
|
|
||||||
onPressed() async {
|
onPressed() async {
|
||||||
await Clipboard.setData(ClipboardData(text: toCopy));
|
await Clipboard.setData(ClipboardData(text: toCopy));
|
||||||
sm.hideCurrentSnackBar();
|
sm.hideCurrentSnackBar();
|
||||||
@ -27,14 +23,15 @@ class CopyButton extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return showLabel
|
return showLabel
|
||||||
? TextButton.icon(
|
? ADTextButton(
|
||||||
|
icon: Icons.content_copy,
|
||||||
|
iconSize: kButtonIconSizeLarge,
|
||||||
|
label: kLabelCopy,
|
||||||
onPressed: onPressed,
|
onPressed: onPressed,
|
||||||
icon: icon,
|
|
||||||
label: const Text(kLabelCopy),
|
|
||||||
)
|
)
|
||||||
: ADIconButton(
|
: ADIconButton(
|
||||||
icon: Icons.content_copy,
|
icon: Icons.content_copy,
|
||||||
iconSize: 18,
|
iconSize: kButtonIconSizeLarge,
|
||||||
tooltip: kLabelCopy,
|
tooltip: kLabelCopy,
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
visualDensity: VisualDensity.compact,
|
visualDensity: VisualDensity.compact,
|
||||||
|
@ -14,18 +14,13 @@ class DiscordButton extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var label = text ?? 'Discord Server';
|
var label = text ?? 'Discord Server';
|
||||||
return FilledButton.icon(
|
return ADFilledButton(
|
||||||
|
icon: Icons.discord,
|
||||||
|
iconSize: kButtonIconSizeLarge,
|
||||||
|
label: label,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
launchUrl(Uri.parse(kDiscordUrl));
|
launchUrl(Uri.parse(kDiscordUrl));
|
||||||
},
|
},
|
||||||
icon: const Icon(
|
|
||||||
Icons.discord,
|
|
||||||
size: 20.0,
|
|
||||||
),
|
|
||||||
label: Text(
|
|
||||||
label,
|
|
||||||
style: kTextStyleButton,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,29 +16,13 @@ class RepoButton extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var label = text ?? "GitHub";
|
var label = text ?? "GitHub";
|
||||||
if (icon == null) {
|
return ADFilledButton(
|
||||||
return FilledButton(
|
icon: icon,
|
||||||
onPressed: () {
|
iconSize: kButtonIconSizeLarge,
|
||||||
launchUrl(Uri.parse(kGitUrl));
|
label: label,
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: kTextStyleButton,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return FilledButton.icon(
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
launchUrl(Uri.parse(kGitUrl));
|
launchUrl(Uri.parse(kGitUrl));
|
||||||
},
|
},
|
||||||
icon: Icon(
|
|
||||||
icon,
|
|
||||||
size: 20.0,
|
|
||||||
),
|
|
||||||
label: Text(
|
|
||||||
label,
|
|
||||||
style: kTextStyleButton,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:apidash/utils/utils.dart';
|
import 'package:apidash/utils/utils.dart';
|
||||||
@ -22,11 +23,6 @@ class SaveInDownloadsButton extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var sm = ScaffoldMessenger.of(context);
|
var sm = ScaffoldMessenger.of(context);
|
||||||
const icon = Icon(
|
|
||||||
Icons.download,
|
|
||||||
size: 18,
|
|
||||||
);
|
|
||||||
const label = kLabelDownload;
|
|
||||||
final onPressed = (content != null)
|
final onPressed = (content != null)
|
||||||
? () => saveToDownloads(
|
? () => saveToDownloads(
|
||||||
sm,
|
sm,
|
||||||
@ -38,17 +34,19 @@ class SaveInDownloadsButton extends StatelessWidget {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
return showLabel
|
return showLabel
|
||||||
? TextButton.icon(
|
? ADTextButton(
|
||||||
|
icon: Icons.download,
|
||||||
|
iconSize: kButtonIconSizeLarge,
|
||||||
|
label: kLabelDownload,
|
||||||
onPressed: onPressed,
|
onPressed: onPressed,
|
||||||
icon: icon,
|
|
||||||
label: const Text(label),
|
|
||||||
)
|
)
|
||||||
: IconButton(
|
: ADIconButton(
|
||||||
tooltip: label,
|
icon: Icons.download,
|
||||||
|
iconSize: kButtonIconSizeLarge,
|
||||||
|
onPressed: onPressed,
|
||||||
|
tooltip: kLabelDownload,
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
visualDensity: VisualDensity.compact,
|
visualDensity: VisualDensity.compact,
|
||||||
onPressed: onPressed,
|
|
||||||
icon: icon,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,34 +16,31 @@ class SendButton extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FilledButton(
|
return ADFilledButton(
|
||||||
onPressed: isWorking ? onCancel : onTap,
|
onPressed: isWorking ? onCancel : onTap,
|
||||||
child: Row(
|
items: isWorking
|
||||||
mainAxisSize: MainAxisSize.min,
|
? const [
|
||||||
children: isWorking
|
Text(
|
||||||
? const [
|
kLabelCancel,
|
||||||
Text(
|
style: kTextStyleButton,
|
||||||
kLabelCancel,
|
),
|
||||||
style: kTextStyleButton,
|
kHSpacer10,
|
||||||
),
|
Icon(
|
||||||
kHSpacer10,
|
size: 16,
|
||||||
Icon(
|
Icons.cancel,
|
||||||
size: 16,
|
)
|
||||||
Icons.cancel,
|
]
|
||||||
)
|
: const [
|
||||||
]
|
Text(
|
||||||
: const [
|
kLabelSend,
|
||||||
Text(
|
style: kTextStyleButton,
|
||||||
kLabelSend,
|
),
|
||||||
style: kTextStyleButton,
|
kHSpacer10,
|
||||||
),
|
Icon(
|
||||||
kHSpacer10,
|
size: 16,
|
||||||
Icon(
|
Icons.send,
|
||||||
size: 16,
|
),
|
||||||
Icons.send,
|
],
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,10 @@ enum WindowWidth {
|
|||||||
final double value;
|
final double value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const kButtonIconSizeSmall = 14.0;
|
||||||
|
const kButtonIconSizeMedium = 16.0;
|
||||||
|
const kButtonIconSizeLarge = 18.0;
|
||||||
|
|
||||||
const kBorderRadius4 = BorderRadius.all(Radius.circular(4));
|
const kBorderRadius4 = BorderRadius.all(Radius.circular(4));
|
||||||
const kBorderRadius6 = BorderRadius.all(Radius.circular(6));
|
const kBorderRadius6 = BorderRadius.all(Radius.circular(6));
|
||||||
const kBorderRadius8 = BorderRadius.all(Radius.circular(8));
|
const kBorderRadius8 = BorderRadius.all(Radius.circular(8));
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../tokens/tokens.dart';
|
||||||
|
|
||||||
|
class ADFilledButton extends StatelessWidget {
|
||||||
|
const ADFilledButton({
|
||||||
|
super.key,
|
||||||
|
this.icon,
|
||||||
|
this.iconSize,
|
||||||
|
this.label,
|
||||||
|
this.items,
|
||||||
|
this.isTonal = false,
|
||||||
|
this.visualDensity,
|
||||||
|
this.onPressed,
|
||||||
|
});
|
||||||
|
|
||||||
|
final IconData? icon;
|
||||||
|
final double? iconSize;
|
||||||
|
final String? label;
|
||||||
|
final List<Widget>? items;
|
||||||
|
final bool isTonal;
|
||||||
|
final VisualDensity? visualDensity;
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
Widget child = Text(
|
||||||
|
label ?? "",
|
||||||
|
style: kTextStyleButton,
|
||||||
|
);
|
||||||
|
if (items != null) {
|
||||||
|
child = Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: items ?? [],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (icon != null && items == null)
|
||||||
|
? (isTonal
|
||||||
|
? FilledButton.tonalIcon(
|
||||||
|
icon: Icon(
|
||||||
|
icon,
|
||||||
|
size: iconSize ?? kButtonIconSizeMedium,
|
||||||
|
),
|
||||||
|
label: child,
|
||||||
|
onPressed: onPressed,
|
||||||
|
)
|
||||||
|
: FilledButton.icon(
|
||||||
|
icon: Icon(
|
||||||
|
icon,
|
||||||
|
size: iconSize ?? kButtonIconSizeMedium,
|
||||||
|
),
|
||||||
|
label: child,
|
||||||
|
onPressed: onPressed,
|
||||||
|
))
|
||||||
|
: (isTonal
|
||||||
|
? FilledButton.tonal(
|
||||||
|
onPressed: onPressed,
|
||||||
|
child: child,
|
||||||
|
)
|
||||||
|
: FilledButton(
|
||||||
|
onPressed: onPressed,
|
||||||
|
child: child,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import '../tokens/tokens.dart';
|
||||||
|
|
||||||
class ADIconButton extends StatelessWidget {
|
class ADIconButton extends StatelessWidget {
|
||||||
const ADIconButton({
|
const ADIconButton({
|
||||||
@ -24,7 +25,7 @@ class ADIconButton extends StatelessWidget {
|
|||||||
tooltip: tooltip,
|
tooltip: tooltip,
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
icon,
|
icon,
|
||||||
size: iconSize ?? 16,
|
size: iconSize ?? kButtonIconSizeMedium,
|
||||||
),
|
),
|
||||||
color: color,
|
color: color,
|
||||||
visualDensity: visualDensity,
|
visualDensity: visualDensity,
|
||||||
|
38
packages/apidash_design_system/lib/widgets/button_text.dart
Normal file
38
packages/apidash_design_system/lib/widgets/button_text.dart
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../tokens/tokens.dart';
|
||||||
|
|
||||||
|
class ADTextButton extends StatelessWidget {
|
||||||
|
const ADTextButton({
|
||||||
|
super.key,
|
||||||
|
this.icon,
|
||||||
|
this.iconSize,
|
||||||
|
this.label,
|
||||||
|
this.onPressed,
|
||||||
|
});
|
||||||
|
|
||||||
|
final IconData? icon;
|
||||||
|
final double? iconSize;
|
||||||
|
final String? label;
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var child = Text(
|
||||||
|
label ?? "",
|
||||||
|
style: kTextStyleButton,
|
||||||
|
);
|
||||||
|
return icon != null
|
||||||
|
? TextButton.icon(
|
||||||
|
icon: Icon(
|
||||||
|
icon,
|
||||||
|
size: iconSize ?? kButtonIconSizeMedium,
|
||||||
|
),
|
||||||
|
label: child,
|
||||||
|
onPressed: onPressed,
|
||||||
|
)
|
||||||
|
: TextButton(
|
||||||
|
onPressed: onPressed,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
|
export 'button_filled.dart';
|
||||||
export 'button_icon.dart';
|
export 'button_icon.dart';
|
||||||
|
export 'button_text.dart';
|
||||||
export 'checkbox.dart';
|
export 'checkbox.dart';
|
||||||
export 'dropdown.dart';
|
export 'dropdown.dart';
|
||||||
export 'popup_menu.dart';
|
export 'popup_menu.dart';
|
||||||
|
Reference in New Issue
Block a user