140 lines
4.4 KiB
Dart
Raw Normal View History

2025-07-30 22:38:44 +07:00
import 'package:flutter/material.dart';
import '../constants/colors.dart';
enum ButtonStyle { filled, outlined }
class Button extends StatelessWidget {
const Button.filled({
super.key,
required this.onPressed,
required this.label,
this.style = ButtonStyle.filled,
this.color = AppColors.primary,
this.textColor = Colors.white,
this.width,
this.height = 50.0,
this.borderRadius = 16.0,
this.icon,
this.disabled = false,
this.fontSize = 16.0,
2025-07-31 19:25:45 +07:00
this.elevation,
this.labelStyle,
2025-07-31 23:22:34 +07:00
this.mainAxisAlignment = MainAxisAlignment.center,
this.crossAxisAlignment = CrossAxisAlignment.center,
2025-07-30 22:38:44 +07:00
});
const Button.outlined({
super.key,
required this.onPressed,
required this.label,
this.style = ButtonStyle.outlined,
this.color = Colors.transparent,
this.textColor = AppColors.primary,
this.width,
this.height = 50.0,
this.borderRadius = 16.0,
this.icon,
this.disabled = false,
this.fontSize = 16.0,
2025-07-31 19:25:45 +07:00
this.elevation,
this.labelStyle,
2025-07-31 23:22:34 +07:00
this.mainAxisAlignment = MainAxisAlignment.center,
this.crossAxisAlignment = CrossAxisAlignment.center,
2025-07-30 22:38:44 +07:00
});
2025-08-04 20:40:25 +07:00
final Function()? onPressed;
2025-07-30 22:38:44 +07:00
final String label;
final ButtonStyle style;
final Color color;
final Color textColor;
final double? width;
final double height;
final double borderRadius;
2025-07-31 19:25:45 +07:00
final double? elevation;
2025-07-30 22:38:44 +07:00
final Widget? icon;
final bool disabled;
final double fontSize;
2025-07-31 19:25:45 +07:00
final TextStyle? labelStyle;
2025-07-31 23:22:34 +07:00
final MainAxisAlignment mainAxisAlignment;
final CrossAxisAlignment crossAxisAlignment;
2025-07-30 22:38:44 +07:00
@override
Widget build(BuildContext context) {
return SizedBox(
height: height,
width: width,
child: style == ButtonStyle.filled
? ElevatedButton(
onPressed: disabled ? null : onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: color,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadius),
),
2025-07-31 19:25:45 +07:00
elevation: elevation,
2025-07-30 22:38:44 +07:00
padding: const EdgeInsets.symmetric(horizontal: 16.0),
),
child: Row(
2025-07-31 23:22:34 +07:00
mainAxisAlignment: mainAxisAlignment,
crossAxisAlignment: crossAxisAlignment,
2025-07-30 22:38:44 +07:00
children: [
icon ?? const SizedBox.shrink(),
if (icon != null) const SizedBox(width: 10.0),
Flexible(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
label,
2025-07-31 19:25:45 +07:00
style: labelStyle ??
TextStyle(
color: disabled ? Colors.grey : textColor,
fontSize: fontSize,
fontWeight: FontWeight.bold,
),
2025-07-30 22:38:44 +07:00
textAlign: TextAlign.center,
),
),
),
],
),
)
: OutlinedButton(
onPressed: disabled ? null : onPressed,
style: OutlinedButton.styleFrom(
backgroundColor: color,
side: const BorderSide(color: AppColors.primary),
2025-07-30 22:38:44 +07:00
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadius),
),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
),
child: Row(
2025-07-31 23:22:34 +07:00
mainAxisAlignment: mainAxisAlignment,
crossAxisAlignment: crossAxisAlignment,
2025-07-30 22:38:44 +07:00
mainAxisSize: MainAxisSize.min,
children: [
icon ?? const SizedBox.shrink(),
if (icon != null) const SizedBox(width: 10.0),
Flexible(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
label,
2025-07-31 19:25:45 +07:00
style: labelStyle ??
TextStyle(
color: disabled ? Colors.grey : textColor,
fontSize: fontSize,
fontWeight: FontWeight.w600,
),
2025-07-30 22:38:44 +07:00
textAlign: TextAlign.center,
),
),
),
],
),
),
);
}
}