section_card.dart 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:flutter/material.dart';
  2. import '../../core/theme/app_colors.dart';
  3. /// Pencil Component/SectionCard — 分组卡片容器
  4. ///
  5. /// 带标题头(16号/600字重)和右侧可选操作按钮,内容区可放任意Widget列表。
  6. /// 圆角8,背景bgCard,padding 16,gap 16。
  7. class SectionCard extends StatelessWidget {
  8. final String title;
  9. final String? actionText;
  10. final IconData? actionIcon;
  11. final VoidCallback? onActionTap;
  12. final List<Widget> children;
  13. final bool showAction;
  14. const SectionCard({
  15. super.key,
  16. required this.title,
  17. this.actionText,
  18. this.actionIcon,
  19. this.onActionTap,
  20. required this.children,
  21. this.showAction = true,
  22. });
  23. @override
  24. Widget build(BuildContext context) {
  25. return Container(
  26. padding: const EdgeInsets.all(16),
  27. decoration: BoxDecoration(
  28. color: AppColors.bgCard,
  29. borderRadius: BorderRadius.circular(8),
  30. ),
  31. child: Column(
  32. crossAxisAlignment: CrossAxisAlignment.start,
  33. children: [
  34. // 标题行
  35. Row(
  36. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  37. children: [
  38. Text(
  39. title,
  40. style: const TextStyle(
  41. fontSize: AppFontSizes.subtitle,
  42. fontWeight: FontWeight.w600,
  43. color: AppColors.textPrimary,
  44. ),
  45. ),
  46. if (showAction && (actionText != null || actionIcon != null))
  47. GestureDetector(
  48. onTap: onActionTap,
  49. child: Row(
  50. mainAxisSize: MainAxisSize.min,
  51. children: [
  52. if (actionText != null)
  53. Text(
  54. actionText!,
  55. style: const TextStyle(
  56. fontSize: AppFontSizes.body,
  57. color: AppColors.textSecondary,
  58. ),
  59. ),
  60. if (actionIcon != null) ...[
  61. const SizedBox(width: 2),
  62. Icon(
  63. actionIcon,
  64. size: 16,
  65. color: AppColors.textSecondary,
  66. ),
  67. ],
  68. ],
  69. ),
  70. ),
  71. ],
  72. ),
  73. // 分隔线
  74. if (children.isNotEmpty) ...[
  75. const SizedBox(height: 16),
  76. ...children,
  77. ],
  78. ],
  79. ),
  80. );
  81. }
  82. }