form_section.dart 2.2 KB

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