352 lines
8.1 KiB
Dart
352 lines
8.1 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import '../utils/color_constants.dart';
|
||
|
|
import '../utils/size_utils.dart';
|
||
|
|
|
||
|
|
class CustomButton extends StatelessWidget {
|
||
|
|
CustomButton(
|
||
|
|
{super.key, this.shape,
|
||
|
|
this.padding,
|
||
|
|
this.variant,
|
||
|
|
this.fontStyle,
|
||
|
|
this.alignment,
|
||
|
|
this.margin,
|
||
|
|
this.onTap,
|
||
|
|
this.width,
|
||
|
|
this.height,
|
||
|
|
this.text,
|
||
|
|
this.prefixWidget,
|
||
|
|
this.suffixWidget});
|
||
|
|
|
||
|
|
ButtonShape? shape;
|
||
|
|
|
||
|
|
ButtonPadding? padding;
|
||
|
|
|
||
|
|
ButtonVariant? variant;
|
||
|
|
|
||
|
|
ButtonFontStyle? fontStyle;
|
||
|
|
|
||
|
|
Alignment? alignment;
|
||
|
|
|
||
|
|
EdgeInsetsGeometry? margin;
|
||
|
|
|
||
|
|
VoidCallback? onTap;
|
||
|
|
|
||
|
|
double? width;
|
||
|
|
|
||
|
|
double? height;
|
||
|
|
|
||
|
|
String? text;
|
||
|
|
|
||
|
|
Widget? prefixWidget;
|
||
|
|
|
||
|
|
Widget? suffixWidget;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return alignment != null
|
||
|
|
? Align(
|
||
|
|
alignment: alignment!,
|
||
|
|
child: _buildButtonWidget(),
|
||
|
|
)
|
||
|
|
: _buildButtonWidget();
|
||
|
|
}
|
||
|
|
|
||
|
|
_buildButtonWidget() {
|
||
|
|
return Padding(
|
||
|
|
padding: margin ?? EdgeInsets.zero,
|
||
|
|
child: TextButton(
|
||
|
|
onPressed: onTap,
|
||
|
|
style: _buildTextButtonStyle(),
|
||
|
|
child: _buildButtonWithOrWithoutIcon(),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
_buildButtonWithOrWithoutIcon() {
|
||
|
|
if (prefixWidget != null || suffixWidget != null) {
|
||
|
|
return Row(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
|
children: [
|
||
|
|
prefixWidget ?? const SizedBox(),
|
||
|
|
Text(
|
||
|
|
text ?? "",
|
||
|
|
textAlign: TextAlign.center,
|
||
|
|
style: _setFontStyle(),
|
||
|
|
),
|
||
|
|
suffixWidget ?? const SizedBox(),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
return Text(
|
||
|
|
text ?? "",
|
||
|
|
textAlign: TextAlign.center,
|
||
|
|
style: _setFontStyle(),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
_buildTextButtonStyle() {
|
||
|
|
return TextButton.styleFrom(
|
||
|
|
fixedSize: Size(
|
||
|
|
width ?? double.maxFinite,
|
||
|
|
height ?? getVerticalSize(40),
|
||
|
|
),
|
||
|
|
padding: _setPadding(),
|
||
|
|
backgroundColor: _setColor(),
|
||
|
|
side: _setTextButtonBorder(),
|
||
|
|
shape: RoundedRectangleBorder(
|
||
|
|
borderRadius: _setBorderRadius(),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
_setPadding() {
|
||
|
|
switch (padding) {
|
||
|
|
case ButtonPadding.PaddingT14:
|
||
|
|
return getPadding(
|
||
|
|
top: 14,
|
||
|
|
right: 14,
|
||
|
|
bottom: 14,
|
||
|
|
);
|
||
|
|
case ButtonPadding.PaddingT7:
|
||
|
|
return getPadding(
|
||
|
|
top: 7,
|
||
|
|
right: 7,
|
||
|
|
bottom: 7,
|
||
|
|
);
|
||
|
|
case ButtonPadding.PaddingAll7:
|
||
|
|
return getPadding(
|
||
|
|
all: 7,
|
||
|
|
);
|
||
|
|
case ButtonPadding.PaddingAll3:
|
||
|
|
return getPadding(
|
||
|
|
all: 3,
|
||
|
|
);
|
||
|
|
default:
|
||
|
|
return getPadding(
|
||
|
|
all: 14,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
_setColor() {
|
||
|
|
switch (variant) {
|
||
|
|
case ButtonVariant.FillBlue50:
|
||
|
|
return ColorConstant.blue50;
|
||
|
|
case ButtonVariant.FillDeeporangeA10033:
|
||
|
|
return ColorConstant.deepOrangeA10033;
|
||
|
|
case ButtonVariant.FillGray10001:
|
||
|
|
return ColorConstant.gray10001;
|
||
|
|
case ButtonVariant.FillLightblue100:
|
||
|
|
return ColorConstant.lightBlue100;
|
||
|
|
case ButtonVariant.FillRed200:
|
||
|
|
return ColorConstant.red200;
|
||
|
|
case ButtonVariant.FillGreenA100:
|
||
|
|
return ColorConstant.greenA100;
|
||
|
|
case ButtonVariant.FillBlueA200:
|
||
|
|
return ColorConstant.blueA200;
|
||
|
|
case ButtonVariant.FillBluegray50:
|
||
|
|
return ColorConstant.blueGray50;
|
||
|
|
case ButtonVariant.OutlineBlueA700:
|
||
|
|
return null;
|
||
|
|
default:
|
||
|
|
return ColorConstant.blueA700;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
_setTextButtonBorder() {
|
||
|
|
switch (variant) {
|
||
|
|
case ButtonVariant.OutlineBlueA700:
|
||
|
|
return BorderSide(
|
||
|
|
color: ColorConstant.blueA700,
|
||
|
|
width: getHorizontalSize(
|
||
|
|
1.00,
|
||
|
|
),
|
||
|
|
);
|
||
|
|
case ButtonVariant.FillBlueA700:
|
||
|
|
case ButtonVariant.FillBlue50:
|
||
|
|
case ButtonVariant.FillDeeporangeA10033:
|
||
|
|
case ButtonVariant.FillGray10001:
|
||
|
|
case ButtonVariant.FillLightblue100:
|
||
|
|
case ButtonVariant.FillRed200:
|
||
|
|
case ButtonVariant.FillGreenA100:
|
||
|
|
case ButtonVariant.FillBlueA200:
|
||
|
|
case ButtonVariant.FillBluegray50:
|
||
|
|
return null;
|
||
|
|
default:
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
_setBorderRadius() {
|
||
|
|
switch (shape) {
|
||
|
|
case ButtonShape.RoundedBorder2:
|
||
|
|
return BorderRadius.circular(
|
||
|
|
getHorizontalSize(
|
||
|
|
2.00,
|
||
|
|
),
|
||
|
|
);
|
||
|
|
case ButtonShape.RoundedBorder16:
|
||
|
|
return BorderRadius.circular(
|
||
|
|
getHorizontalSize(
|
||
|
|
16.00,
|
||
|
|
),
|
||
|
|
);
|
||
|
|
case ButtonShape.Square:
|
||
|
|
return BorderRadius.circular(0);
|
||
|
|
default:
|
||
|
|
return BorderRadius.circular(
|
||
|
|
getHorizontalSize(
|
||
|
|
6.00,
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
_setFontStyle() {
|
||
|
|
switch (fontStyle) {
|
||
|
|
case ButtonFontStyle.GilroyMedium14:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.blueA700,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
14,
|
||
|
|
),
|
||
|
|
fontFamily: 'Gilroy',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.GilroyMedium14WhiteA700:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.whiteA700,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
14,
|
||
|
|
),
|
||
|
|
fontFamily: 'Gilroy',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.GilroyMedium16Black900:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.black900,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
16,
|
||
|
|
),
|
||
|
|
fontFamily: 'Gilroy',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.SFUIDisplayBold12:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.whiteA700,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
12,
|
||
|
|
),
|
||
|
|
fontFamily: 'SF UI Display',
|
||
|
|
fontWeight: FontWeight.w700,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.GilroyMedium16BlueA700:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.blueA700,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
16,
|
||
|
|
),
|
||
|
|
fontFamily: 'Gilroy',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.GilroyMedium12:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.deepOrange400,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
12,
|
||
|
|
),
|
||
|
|
fontFamily: 'Gilroy',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.GilroyMedium12Red700:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.red700,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
12,
|
||
|
|
),
|
||
|
|
fontFamily: 'Gilroy',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.InterSemiBold10:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.black90001,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
10,
|
||
|
|
),
|
||
|
|
fontFamily: 'Inter',
|
||
|
|
fontWeight: FontWeight.w600,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.RobotoMedium14:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.whiteA700,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
14,
|
||
|
|
),
|
||
|
|
fontFamily: 'Roboto',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
case ButtonFontStyle.InterRegular14:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.blueGray400,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
14,
|
||
|
|
),
|
||
|
|
fontFamily: 'Inter',
|
||
|
|
fontWeight: FontWeight.w400,
|
||
|
|
);
|
||
|
|
default:
|
||
|
|
return TextStyle(
|
||
|
|
color: ColorConstant.whiteA700,
|
||
|
|
fontSize: getFontSize(
|
||
|
|
16,
|
||
|
|
),
|
||
|
|
fontFamily: 'Gilroy',
|
||
|
|
fontWeight: FontWeight.w500,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
enum ButtonShape {
|
||
|
|
Square,
|
||
|
|
RoundedBorder6,
|
||
|
|
RoundedBorder2,
|
||
|
|
RoundedBorder16,
|
||
|
|
}
|
||
|
|
|
||
|
|
enum ButtonPadding {
|
||
|
|
PaddingAll14,
|
||
|
|
PaddingT14,
|
||
|
|
PaddingT7,
|
||
|
|
PaddingAll7,
|
||
|
|
PaddingAll3,
|
||
|
|
}
|
||
|
|
|
||
|
|
enum ButtonVariant {
|
||
|
|
FillBlueA700,
|
||
|
|
OutlineBlueA700,
|
||
|
|
FillBlue50,
|
||
|
|
FillDeeporangeA10033,
|
||
|
|
FillGray10001,
|
||
|
|
FillLightblue100,
|
||
|
|
FillRed200,
|
||
|
|
FillGreenA100,
|
||
|
|
FillBlueA200,
|
||
|
|
FillBluegray50,
|
||
|
|
}
|
||
|
|
|
||
|
|
enum ButtonFontStyle {
|
||
|
|
GilroyMedium16,
|
||
|
|
GilroyMedium14,
|
||
|
|
GilroyMedium14WhiteA700,
|
||
|
|
GilroyMedium16Black900,
|
||
|
|
SFUIDisplayBold12,
|
||
|
|
GilroyMedium16BlueA700,
|
||
|
|
GilroyMedium12,
|
||
|
|
GilroyMedium12Red700,
|
||
|
|
InterSemiBold10,
|
||
|
|
RobotoMedium14,
|
||
|
|
InterRegular14,
|
||
|
|
}
|