70 lines
2.0 KiB
Dart
70 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../theme/yanting_text.dart';
|
|
import '../theme/yanting_tokens.dart';
|
|
|
|
class AppButton extends StatelessWidget {
|
|
const AppButton({
|
|
required this.label,
|
|
required this.onPressed,
|
|
this.icon,
|
|
this.kind = AppButtonKind.primary,
|
|
this.expand = false,
|
|
super.key,
|
|
});
|
|
|
|
final String label;
|
|
final VoidCallback? onPressed;
|
|
final IconData? icon;
|
|
final AppButtonKind kind;
|
|
final bool expand;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colors = switch (kind) {
|
|
AppButtonKind.primary => (
|
|
YantingColors.primary,
|
|
YantingColors.primaryForeground,
|
|
Colors.transparent,
|
|
),
|
|
AppButtonKind.dark => (
|
|
YantingColors.foreground,
|
|
YantingColors.background,
|
|
Colors.transparent,
|
|
),
|
|
AppButtonKind.accent => (
|
|
YantingColors.brandSoft,
|
|
YantingColors.primaryForeground,
|
|
Colors.transparent,
|
|
),
|
|
AppButtonKind.ghost => (
|
|
YantingColors.background,
|
|
YantingColors.foreground,
|
|
YantingColors.border,
|
|
),
|
|
};
|
|
final child = FilledButton.icon(
|
|
onPressed: onPressed,
|
|
icon: icon == null ? const SizedBox.shrink() : Icon(icon, size: 18),
|
|
label: Text(label),
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: colors.$1,
|
|
foregroundColor: colors.$2,
|
|
disabledBackgroundColor: YantingColors.border,
|
|
disabledForegroundColor: YantingColors.mutedForeground,
|
|
minimumSize: Size(expand ? double.infinity : 0, 44),
|
|
textStyle: YantingText.body.copyWith(fontWeight: FontWeight.w600),
|
|
side: colors.$3 == Colors.transparent
|
|
? BorderSide.none
|
|
: BorderSide(color: colors.$3),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(YantingRadius.md),
|
|
),
|
|
),
|
|
);
|
|
return expand ? SizedBox(width: double.infinity, child: child) : child;
|
|
}
|
|
}
|
|
|
|
enum AppButtonKind { primary, dark, accent, ghost }
|