import 'package:flutter/material.dart'; import 'package:water_management_system/utils/constants.dart'; class CustomButton extends StatelessWidget { final String text; final VoidCallback onPressed; final Color? backgroundColor; final Color? textColor; final double? width; final double? height; final bool? isLoading; final IconData? icon; final double? fontSize; final FontWeight? fontWeight; const CustomButton({ super.key, required this.text, required this.onPressed, this.backgroundColor, this.textColor, this.width, this.height, this.isLoading = false, this.icon, this.fontSize, this.fontWeight, }); @override Widget build(BuildContext context) { return SizedBox( width: width ?? double.infinity, height: height ?? 48, child: ElevatedButton( onPressed: isLoading! ? null : onPressed, style: ElevatedButton.styleFrom( backgroundColor: backgroundColor ?? AppConstants.primaryColor, foregroundColor: textColor ?? Colors.white, elevation: 2, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), ), ), child: isLoading! ? const SizedBox( width: 20, height: 20, child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white), ), ) : Row( mainAxisAlignment: MainAxisAlignment.center, children: [ if (icon != null) ...[ Icon( icon, size: fontSize ?? 16, ), const SizedBox(width: 8), ], Text( text, style: TextStyle( fontSize: fontSize ?? 16, fontWeight: fontWeight ?? FontWeight.w500, ), ), ], ), ), ); } }