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

custom_card.dart 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:flutter/material.dart';
  2. import 'package:water_management_system/utils/constants.dart';
  3. class CustomCard extends StatelessWidget {
  4. final String? title;
  5. final String? subtitle;
  6. final Widget? trailing;
  7. final List<Widget>? children;
  8. final Color? color;
  9. final IconData? icon;
  10. final String? value;
  11. const CustomCard({
  12. super.key,
  13. this.title,
  14. this.subtitle,
  15. this.trailing,
  16. this.children,
  17. this.color,
  18. this.icon,
  19. this.value,
  20. });
  21. @override
  22. Widget build(BuildContext context) {
  23. if (title != null && value != null && icon != null) {
  24. return Container(
  25. padding: const EdgeInsets.all(12),
  26. decoration: BoxDecoration(
  27. color: color?.withOpacity(0.1) ?? Colors.white,
  28. borderRadius: BorderRadius.circular(8),
  29. border: Border.all(color: color?.withOpacity(0.3) ?? Colors.grey[300]!),
  30. ),
  31. child: Column(
  32. crossAxisAlignment: CrossAxisAlignment.start,
  33. children: [
  34. Icon(icon, color: color ?? AppConstants.primaryColor, size: 24),
  35. const SizedBox(height: 8),
  36. Text(title!, style: TextStyle(fontSize: 12, color: Colors.grey[600])),
  37. const SizedBox(height: 4),
  38. Text(value!, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: color ?? AppConstants.primaryColor)),
  39. ],
  40. ),
  41. );
  42. }
  43. return Card(
  44. margin: const EdgeInsets.symmetric(vertical: 4),
  45. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
  46. elevation: 2,
  47. child: Padding(
  48. padding: const EdgeInsets.all(16),
  49. child: Column(
  50. crossAxisAlignment: CrossAxisAlignment.start,
  51. children: [
  52. if (title != null || trailing != null)
  53. Row(children: [
  54. if (title != null) Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
  55. Text(title!, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
  56. if (subtitle != null) Text(subtitle!, style: TextStyle(color: Colors.grey[600], fontSize: 12)),
  57. ])),
  58. if (trailing != null) trailing!,
  59. ]),
  60. if (children != null) ...children!,
  61. ],
  62. ),
  63. ),
  64. );
  65. }
  66. }