JuiButton constructor

JuiButton({
  1. Key? key,
  2. required String label,
  3. required VoidCallback? onPressed,
  4. Widget? icon,
  5. VoidCallback? onLongPress,
  6. ButtonStyle? style,
  7. FocusNode? focusNode,
  8. bool autofocus = false,
  9. Clip clipBehavior = Clip.none,
  10. double width = double.infinity,
  11. Color? textColor = JuiColors.white,
  12. Color? backgroundColor = JuiColors.primaryColor,
  13. bool? disabled,
  14. bool? loading,
  15. Color? disabledBackgroundColor = const Color(0xFFD3D3D3),
})

Implementation

JuiButton({
  Key? key,
  required String label,
  required VoidCallback? onPressed,
  Widget? icon,
  VoidCallback? onLongPress,
  ButtonStyle? style,
  FocusNode? focusNode,
  bool autofocus = false,
  Clip clipBehavior = Clip.none,
  double width = double.infinity,
  Color? textColor = JuiColors.white,
  Color? backgroundColor = JuiColors.primaryColor,
  bool? disabled,
  bool? loading,
  Color? disabledBackgroundColor = const Color(0xFFD3D3D3),
}) : super(
        key: key,
        onPressed: (disabled == true || loading == true) ? null : onPressed,
        onLongPress: (disabled == true || loading == true) ? null : onLongPress,
        style: ButtonStyle(
          foregroundColor: MaterialStateProperty.all<Color?>(
            (disabled == true || loading == true) ? Colors.black.withOpacity(0.32) : textColor,
          ),
          backgroundColor: MaterialStateProperty.all<Color?>(
            (disabled == true || loading == true) ? disabledBackgroundColor : backgroundColor,
          ),
          fixedSize: MaterialStateProperty.all<Size?>(Size(width, JuiBreakpoints.b48)),
          elevation: MaterialStateProperty.all<double>(0),
          shape: MaterialStateProperty.all<OutlinedBorder?>(
            RoundedRectangleBorder(borderRadius: BorderRadius.circular(JuiBreakpoints.b24)),
          ),
        ),
        focusNode: focusNode,
        autofocus: autofocus,
        clipBehavior: clipBehavior,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (icon != null) icon,
            if (loading == true)
              SizedBox(
                width: JuiBreakpoints.b16,
                height: JuiBreakpoints.b16,
                child: CircularProgressIndicator(
                  strokeWidth: 2.0.r,
                  color: Colors.black.withOpacity(0.32),
                ),
              ),
            if (icon != null) SizedBox(width: JuiBreakpoints.b8),
            if (loading == true) SizedBox(width: JuiBreakpoints.b16),
            Text(
              label,
              style: const TextStyle().regularSemiBold(
                color: ((disabled == true || loading == true) &&
                        disabledBackgroundColor == const Color(0xFFD3D3D3))
                    ? Colors.black.withOpacity(0.32)
                    : textColor,
              ),
            ),
            if (loading == true) SizedBox(width: JuiBreakpoints.b32),
          ],
        ),
      );