action_bar.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import 'package:flutter/material.dart';
  2. import '../../core/theme/app_colors.dart';
  3. /// Pencil Component/ActionBar — 底部操作栏
  4. ///
  5. /// 水平排列三个按钮:重置(可选)、存草稿、提交。
  6. /// 所有按钮圆角22,总高度72,padding 16,gap 12,背景bgCard。
  7. class ActionBar extends StatelessWidget {
  8. final String? leftLabel;
  9. final String centerLabel;
  10. final String rightLabel;
  11. final VoidCallback? onLeftTap;
  12. final VoidCallback? onCenterTap;
  13. final VoidCallback? onRightTap;
  14. final bool showLeft;
  15. const ActionBar({
  16. super.key,
  17. this.leftLabel,
  18. required this.centerLabel,
  19. required this.rightLabel,
  20. this.onLeftTap,
  21. this.onCenterTap,
  22. this.onRightTap,
  23. this.showLeft = true,
  24. });
  25. @override
  26. Widget build(BuildContext context) {
  27. return Container(
  28. height: 72,
  29. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
  30. decoration: const BoxDecoration(
  31. color: AppColors.bgCard,
  32. ),
  33. child: Row(
  34. children: [
  35. // 左侧重置按钮(可选显示)
  36. if (showLeft && leftLabel != null) ...[
  37. Expanded(
  38. child: _ActionButton(
  39. label: leftLabel!,
  40. backgroundColor: AppColors.bgCard,
  41. textColor: AppColors.textSecondary,
  42. onTap: onLeftTap,
  43. ),
  44. ),
  45. const SizedBox(width: 12),
  46. ],
  47. // 中间存草稿按钮
  48. Expanded(
  49. child: _ActionButton(
  50. label: centerLabel,
  51. backgroundColor: AppColors.primaryLight,
  52. textColor: AppColors.primary,
  53. onTap: onCenterTap,
  54. ),
  55. ),
  56. const SizedBox(width: 12),
  57. // 右侧提交按钮
  58. Expanded(
  59. child: _ActionButton(
  60. label: rightLabel,
  61. backgroundColor: AppColors.primary,
  62. textColor: AppColors.bgCard,
  63. onTap: onRightTap,
  64. ),
  65. ),
  66. ],
  67. ),
  68. );
  69. }
  70. }
  71. class _ActionButton extends StatelessWidget {
  72. final String label;
  73. final Color backgroundColor;
  74. final Color textColor;
  75. final VoidCallback? onTap;
  76. const _ActionButton({
  77. required this.label,
  78. required this.backgroundColor,
  79. required this.textColor,
  80. this.onTap,
  81. });
  82. @override
  83. Widget build(BuildContext context) {
  84. return SizedBox(
  85. height: 40,
  86. child: Material(
  87. color: backgroundColor,
  88. borderRadius: BorderRadius.circular(22),
  89. child: InkWell(
  90. onTap: onTap,
  91. borderRadius: BorderRadius.circular(22),
  92. child: Center(
  93. child: Text(
  94. label,
  95. style: TextStyle(
  96. fontSize: AppFontSizes.body,
  97. fontWeight: FontWeight.w500,
  98. color: textColor,
  99. ),
  100. ),
  101. ),
  102. ),
  103. ),
  104. );
  105. }
  106. }