form_section.dart 2.3 KB

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