智慧水务管理系统 - 精河县供水工程综合管理平台

custom_button.dart 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:flutter/material.dart';
  2. import 'package:water_management_system/utils/constants.dart';
  3. class CustomButton extends StatelessWidget {
  4. final String text;
  5. final VoidCallback onPressed;
  6. final Color? backgroundColor;
  7. final Color? textColor;
  8. final double? width;
  9. final double? height;
  10. final bool? isLoading;
  11. final IconData? icon;
  12. final double? fontSize;
  13. final FontWeight? fontWeight;
  14. const CustomButton({
  15. super.key,
  16. required this.text,
  17. required this.onPressed,
  18. this.backgroundColor,
  19. this.textColor,
  20. this.width,
  21. this.height,
  22. this.isLoading = false,
  23. this.icon,
  24. this.fontSize,
  25. this.fontWeight,
  26. });
  27. @override
  28. Widget build(BuildContext context) {
  29. return SizedBox(
  30. width: width ?? double.infinity,
  31. height: height ?? 48,
  32. child: ElevatedButton(
  33. onPressed: isLoading! ? null : onPressed,
  34. style: ElevatedButton.styleFrom(
  35. backgroundColor: backgroundColor ?? AppConstants.primaryColor,
  36. foregroundColor: textColor ?? Colors.white,
  37. elevation: 2,
  38. shape: RoundedRectangleBorder(
  39. borderRadius: BorderRadius.circular(8),
  40. ),
  41. ),
  42. child: isLoading!
  43. ? const SizedBox(
  44. width: 20,
  45. height: 20,
  46. child: CircularProgressIndicator(
  47. strokeWidth: 2,
  48. valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
  49. ),
  50. )
  51. : Row(
  52. mainAxisAlignment: MainAxisAlignment.center,
  53. children: [
  54. if (icon != null) ...[
  55. Icon(
  56. icon,
  57. size: fontSize ?? 16,
  58. ),
  59. const SizedBox(width: 8),
  60. ],
  61. Text(
  62. text,
  63. style: TextStyle(
  64. fontSize: fontSize ?? 16,
  65. fontWeight: fontWeight ?? FontWeight.w500,
  66. ),
  67. ),
  68. ],
  69. ),
  70. ),
  71. );
  72. }
  73. }