first commit
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
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,
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
final Function() onPressed;
|
||||
final String label;
|
||||
final ButtonStyle style;
|
||||
final Color color;
|
||||
final Color textColor;
|
||||
final double? width;
|
||||
final double height;
|
||||
final double borderRadius;
|
||||
final Widget? icon;
|
||||
final bool disabled;
|
||||
final double fontSize;
|
||||
|
||||
@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),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
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,
|
||||
style: TextStyle(
|
||||
color: disabled ? Colors.grey : textColor,
|
||||
fontSize: fontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: OutlinedButton(
|
||||
onPressed: disabled ? null : onPressed,
|
||||
style: OutlinedButton.styleFrom(
|
||||
backgroundColor: color,
|
||||
side: const BorderSide(color: Colors.grey),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
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,
|
||||
style: TextStyle(
|
||||
color: disabled ? Colors.grey : textColor,
|
||||
fontSize: fontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user