| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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<Color>(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,
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
|