getButton function

Widget getButton(
  1. String text,
  2. Function function, {
  3. bool disabled = false,
  4. Color? bgColor,
  5. bool withCorners = true,
  6. Color? textColor,
  7. FontWeight weight = FontWeight.w500,
  8. EdgeInsetsGeometry? insetsGeometry,
  9. String? icon,
  10. bool isBorder = false,
  11. Color borderColor = Colors.transparent,
  12. 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),
                ],
              ),
      ),
    ),
  );
}