You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/lib/widgets/buttons/custom_button.dart

97 lines
3.3 KiB
Dart

2 months ago
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
2 months ago
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
class CustomButton extends StatelessWidget {
final String text;
3 weeks ago
final String? icon;
2 months ago
final VoidCallback onPressed;
final Color backgroundColor;
final Color borderColor;
final Color textColor;
3 weeks ago
final double? borderRadius;
2 months ago
final double borderWidth;
final EdgeInsetsGeometry padding;
3 weeks ago
final double? fontSize;
2 months ago
final String? fontFamily;
final FontWeight fontWeight;
final bool isDisabled;
2 months ago
final Color? iconColor;
3 weeks ago
final double? height;
final double? width;
3 weeks ago
final double? iconSize;
final TextOverflow? textOverflow;
final BorderSide? borderSide;
2 months ago
3 weeks ago
const CustomButton({
super.key,
required this.text,
required this.onPressed,
this.backgroundColor = const Color(0xFFED1C2B),
this.borderColor = const Color(0xFFED1C2B),
this.textColor = Colors.white,
this.borderRadius,
this.borderWidth = 2,
this.padding = const EdgeInsets.fromLTRB(8, 10, 8, 10),
this.fontSize,
this.fontFamily,
this.fontWeight = FontWeight.w500,
this.isDisabled = false,
this.icon,
this.iconColor = Colors.white,
this.height,
this.width,
this.iconSize,
this.textOverflow,
this.borderSide,
});
2 months ago
@override
Widget build(BuildContext context) {
3 weeks ago
final radius = borderRadius ?? (12.r);
final iconS = iconSize ?? (24.h);
final fontS = fontSize ?? (16.f);
2 months ago
return GestureDetector(
onTap: isDisabled ? null : onPressed,
child: Container(
1 week ago
height: height ?? (56.h),
width: width,
padding: padding,
2 months ago
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
color: isDisabled ? backgroundColor.withOpacity(.5) : backgroundColor,
3 weeks ago
borderRadius: radius,
customBorder: BorderRadius.circular(radius),
side: borderSide ?? BorderSide(width: borderWidth.h, color: isDisabled ? borderColor.withValues(alpha: 0.5) : borderColor)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (icon != null)
Padding(
3 weeks ago
padding: text.isNotEmpty ? EdgeInsets.only(right: 8.h, left: 8.h) : EdgeInsets.zero,
child: Utils.buildSvgWithAssets(icon: icon!, iconColor: iconColor, isDisabled: isDisabled, width: iconS, height: iconS),
2 months ago
),
Visibility(
visible: text.isNotEmpty,
child: Padding(
padding: EdgeInsets.only(top: 0),
child: Text(
text,
overflow: textOverflow,
style: context.dynamicTextStyle(
3 weeks ago
fontSize: fontS,
color: isDisabled ? textColor.withOpacity(0.5) : textColor,
letterSpacing: 0,
fontWeight: fontWeight,
),
),
),
),
],
2 months ago
),
));
2 months ago
}
}