primary static method

Widget primary({
  1. required String text,
  2. required VoidCallback? onPressed,
  3. bool loading = false,
  4. ButtonSize size = ButtonSize.md,
  5. Widget? prefixIcon,
  6. Widget? suffixIcon,
  7. Color? backgroundColor,
  8. Color? textColor,
  9. bool? showShadow,
  10. MaterialTapTargetSize? tapTargetSize,
  11. bool stretch = true,
  12. Color? boarderColor,
  13. EdgeInsetsGeometry margin = EdgeInsets.zero,
  14. EdgeInsetsGeometry? padding,
})

Implementation

static Widget primary(
    {required String text,
    required VoidCallback? onPressed,
    bool loading = false,
    ButtonSize size = ButtonSize.md,
    Widget? prefixIcon,
    Widget? suffixIcon,
    Color? backgroundColor,
    Color? textColor,
    bool? showShadow,
    MaterialTapTargetSize? tapTargetSize,
    bool stretch = true,
    Color? boarderColor,
    EdgeInsetsGeometry margin = EdgeInsets.zero,
    EdgeInsetsGeometry? padding}) {
  return Padding(
    padding: margin,
    child: TextButton(
        style: TextButton.styleFrom(
            tapTargetSize: tapTargetSize,
            minimumSize: Size(stretch ? double.infinity : 0, 0.0),
            padding: padding ?? size.titlePadding,
            shape: rectBorderRadiusX(40, boarderColor),
            backgroundColor: backgroundColor ?? KashiColors.primaryColor),
        onPressed: !loading
            ? () {
                HapticFeedback.lightImpact();
                onPressed?.call();
              }
            : null,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: stretch ? MainAxisSize.max : MainAxisSize.min,
          children: [
            loading
                ? Container(
                    margin: const EdgeInsets.only(right: 12),
                    width: 12,
                    height: 12,
                    child: const CircularProgressIndicator(
                      strokeWidth: 2,
                      color: Colors.white,
                    ),
                  )
                : const SizedBox.shrink(),
            if (prefixIcon != null)
              Padding(
                padding: const EdgeInsets.only(right: 8.0),
                child: prefixIcon,
              ),
            Flexible(
              child: Text(
                text,
                style: KashiTheme.sh2SemiBold
                    .copyWith(color: textColor ?? Colors.white)
                    .copyWith(
                      fontWeight: size.fontWeight,
                      fontSize: size.fontSize,
                    )
                    .toDMSanFontsFamily(),
              ),
            ),
            if (suffixIcon != null)
              Padding(
                padding: const EdgeInsets.only(left: 8.0),
                child: suffixIcon,
              ),
          ],
        )),
  );
}