loadButton function

Widget loadButton({
  1. double? buttonHeight,
  2. double? buttonWidth,
  3. Color? textColor,
  4. double? textSize,
  5. double? buttonElevation,
  6. required dynamic onPressed(),
  7. required String buttonText,
  8. required BuildContext context,
  9. required bool isLoading,
})

Loading Button widget with conditional visibility.

Used to create a button that shows a loading animation when isLoading is true, otherwise, it shows a regular button.

Parameters:

  • buttonHeight: Height of the button.
  • buttonWidth: Width of the button.
  • textColor: Color of the button text.
  • textSize: Font size of the button text.
  • buttonElevation: Elevation of the button.
  • onPressed: Callback function when the button is pressed.
  • buttonText: Text displayed on the button.
  • context: Build context for calculating default width.
  • isLoading: Flag to determine whether to show loading animation or button.

Implementation

Widget loadButton({
  double? buttonHeight,
  double? buttonWidth,
  Color? textColor,
  double? textSize,
  double? buttonElevation,
  required Function() onPressed,
  required String buttonText,
  required BuildContext context,
  required bool isLoading,
}) {
  return Visibility(
    visible: !isLoading,
    replacement: loadingAnimation(
      loadingType: LoadingAnimationWidget.beat(
        color: AppColors.primaryColor,
        size: getWidth(10, context),
      ),
    ),
    child: Container(
      width: buttonWidth ?? getWidth(80, context),
      height: buttonHeight ?? 60.0,
      padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
      child: FilledButton(
        style: ElevatedButton.styleFrom(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20.0),
          ),
          elevation: buttonElevation ?? 0.0,
        ),
        onPressed: onPressed,
        child: Text(
          buttonText,
          style: TextStyle(
            fontSize: textSize ?? getWidth(10, context),
            color: textColor ?? Colors.white,
          ),
        ),
      ),
    ),
  );
}