primaryButton static method

Widget primaryButton({
  1. required void onPressed(),
  2. void onFocusChange(
    1. bool
    )?,
  3. void onLongPress()?,
  4. Color? backgroundColor,
  5. EdgeInsetsGeometry? padding,
  6. MainAxisSize mainAxisSize = MainAxisSize.max,
  7. Widget? leadingIcon,
  8. Widget? trailingIcon,
  9. Widget? child,
  10. required String buttonTitle,
  11. TextStyle? textStyle,
  12. double? fontSize,
  13. FontWeight? textFontWeight,
  14. double? elevation,
  15. Color? textColor,
  16. double? borderRadius,
  17. bool isDisabled = false,
})

Implementation

static Widget primaryButton({
  required void Function() onPressed,
  void Function(bool)? onFocusChange,
  void Function()? onLongPress,
  Color? backgroundColor,
  EdgeInsetsGeometry? padding,
  MainAxisSize mainAxisSize = MainAxisSize.max,
  Widget? leadingIcon,
  Widget? trailingIcon,
  Widget? child,
  required String buttonTitle,
  TextStyle? textStyle,
  double? fontSize,
  FontWeight? textFontWeight,
  double? elevation,
  Color? textColor,
  double? borderRadius,
  bool isDisabled = false,
}) {
  return ElevatedButton(
    onPressed: onPressed,
    onFocusChange: onFocusChange,
    onLongPress: onLongPress,
    style: ElevatedButton.styleFrom(
      overlayColor: Colors.black,
      backgroundColor: isDisabled
          ? (backgroundColor?.withOpacity(0.5) ??
              AppColors.primary.withOpacity(0.5))
          : (backgroundColor ?? AppColors.primary),
      padding: padding ??
          const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(borderRadius ?? 12.0),
      ),
      elevation: elevation ?? 2.0,
    ),
    child: child ??
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: mainAxisSize,
          children: [
            if (leadingIcon != null) ...[leadingIcon],
            Expanded(
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 8.0),
                child: Text(
                  buttonTitle,
                  style: textStyle ??
                      const TextStyle(
                          fontSize: 18.0, color: AppColors.secondary),
                  textAlign: leadingIcon != null ? null : TextAlign.center,
                ),
              ),
            ),
            if (trailingIcon != null) ...[trailingIcon],
          ],
        ),
  );
}