import 'package:flutter/material.dart'; import 'package:flutter_lucide/flutter_lucide.dart'; import 'package:provider/provider.dart'; import '../Provider/language_provider.dart'; import '../config/language/language_enum.dart'; import '../utils/colors.dart'; import 'custom_text.dart'; class CustomButton extends StatelessWidget { CustomButton({ super.key, required this.title, this.onClick, this.backgroundColor, this.height, this.width, this.padding, this.icon, this.fontSize, this.iconSize, this.borderRadius = 25, this.txtColor = Colors.white, this.loadercolor = AppColors.secondaryColor, this.borderColor = AppColors.primaryColor, this.isloading = false, }); final String title; final VoidCallback? onClick; Color? backgroundColor; final double? height; final double? width; final EdgeInsetsGeometry? padding; final double? fontSize; final double? iconSize; final double? borderRadius; bool? isloading; Color loadercolor; Color txtColor; Color borderColor; IconData? icon; @override Widget build(BuildContext context) { LanguageProvider? languageProvider; try { languageProvider = Provider.of(context); } catch (e) { debugPrint("LanguageProvider not found"); } bool isArabic = languageProvider?.currentLangCode == Language.ar; String translatedTitle = languageProvider?.translate(title) ?? title; return Padding( padding: padding ?? EdgeInsets.zero, child: SizedBox( width: width, height: height, child: ElevatedButton( style: ElevatedButton.styleFrom( shape: RoundedRectangleBorder( side: BorderSide(color: borderColor), borderRadius: BorderRadius.circular(borderRadius!), ), ).copyWith( backgroundColor: WidgetStateProperty.all(backgroundColor ?? (Theme.of(context).brightness == Brightness.dark ? AppColors.darkPrimaryColor : AppColors.primaryColor)), ), onPressed: onClick, child: isloading != null && isloading == true ? SizedBox( width: 30, height: 30, child: CircularProgressIndicator( color: loadercolor, strokeWidth: 3, ), ) : FittedBox( fit: BoxFit.scaleDown, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ if (icon != null) Icon(icon, size: iconSize ?? 15), if (icon != null) const SizedBox(width: 6), // spacing between icon & text Txt( text: translatedTitle, textAlign: TextAlign.center, style: isArabic ? TextStyle( fontWeight: FontWeight.w400, fontFamily: 'Baloo_Bhaijaan_2', fontSize: fontSize ?? 16, color: txtColor) : TextStyle( fontWeight: FontWeight.w600, fontFamily: 'Poppins', fontSize: fontSize ?? 16, color: txtColor), ), ], ), ), ), ), ); } }