getButton function
Widget
getButton(
- String text,
- Function function, {
- bool disabled = false,
- Color? bgColor,
- bool withCorners = true,
- Color? textColor,
- FontWeight weight = FontWeight.w500,
- EdgeInsetsGeometry? insetsGeometry,
- String? icon,
- bool isBorder = false,
- Color borderColor = Colors.transparent,
- bool loading = false,
})
Implementation
Widget getButton(
String text,
Function function, {
bool disabled = false,
Color? bgColor,
bool withCorners = true,
Color? textColor,
FontWeight weight = FontWeight.w500,
EdgeInsetsGeometry? insetsGeometry,
String? icon,
bool isBorder = false,
Color borderColor = Colors.transparent,
bool loading = false,
}) {
textColor = textColor ?? MahasColors.whiteColor;
bgColor = bgColor ?? MahasColors.primaryColor.withOpacity(!disabled ? 1 : .5);
double buttonHeight = MahasDimensions.getInputHeight();
double fontSize = MahasDimensions.getInputTextSize();
return InkWell(
onTap: () {
if (!disabled) function();
},
child: Container(
margin: insetsGeometry,
width: double.infinity,
height: buttonHeight,
decoration: ShapeDecoration(
color: loading ? bgColor.withOpacity(0.5) : bgColor,
shape: SmoothRectangleBorder(
side: BorderSide(
width: 1, color: isBorder ? borderColor : Colors.transparent),
borderRadius: SmoothBorderRadius(
cornerRadius: withCorners ? MahasDimensions.getInputRadius() : 0,
cornerSmoothing: withCorners ? 0.5 : 0,
),
),
),
child: Center(
child: loading
? SizedBox(
height: buttonHeight * 0.5,
width: buttonHeight * 0.5,
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(MahasColors.whiteColor),
),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (icon != null) ...[
getIcon(icon, color: MahasColors.whiteColor),
if (text.isNotEmpty) getSpaceWidth(1),
],
getCustomText(text,
color: textColor,
align: TextAlign.center,
weight: weight,
size: fontSize),
],
),
),
),
);
}