| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import 'package:flutter/material.dart';
- import '../../core/theme/app_colors.dart';
- import '../../core/theme/app_colors_extension.dart';
- /// Pencil Component/ActionBar — 底部操作栏
- ///
- /// 水平排列三个按钮:重置(可选)、存草稿、提交。
- /// 所有按钮圆角22,总高度72,padding 16,gap 12,背景bgCard。
- class ActionBar extends StatelessWidget {
- final String? leftLabel;
- final String? centerLabel;
- final String? rightLabel;
- final VoidCallback? onLeftTap;
- final VoidCallback? onCenterTap;
- final VoidCallback? onRightTap;
- final bool showLeft;
- final bool showCenter;
- final bool showRight;
- final bool centerTextOnly;
- const ActionBar({
- super.key,
- this.leftLabel,
- this.centerLabel,
- this.rightLabel,
- this.onLeftTap,
- this.onCenterTap,
- this.onRightTap,
- this.showLeft = true,
- this.showCenter = true,
- this.showRight = true,
- this.centerTextOnly = false,
- });
- @override
- Widget build(BuildContext context) {
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
- return Container(
- height: 72,
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
- decoration: BoxDecoration(
- color: colors.bgCard,
- border: Border(top: BorderSide(color: colors.border, width: 0.5)),
- ),
- child: Row(
- children: _buildButtons(colors),
- ),
- );
- }
- List<Widget> _buildButtons(AppColorsExtension colors) {
- final buttons = <Widget>[];
- void addGap() {
- if (buttons.isNotEmpty) buttons.add(const SizedBox(width: 12));
- }
- if (showLeft && leftLabel != null) {
- buttons.add(Expanded(
- child: _ActionButton(
- label: leftLabel!,
- backgroundColor: colors.bgCard,
- textColor: colors.textSecondary,
- onTap: onLeftTap,
- ),
- ));
- }
- if (showCenter && centerLabel != null) {
- addGap();
- buttons.add(Expanded(
- child: _ActionButton(
- label: centerLabel!,
- backgroundColor: centerTextOnly ? colors.bgCard : colors.primaryLight,
- textColor: centerTextOnly ? colors.textSecondary : colors.primary,
- onTap: onCenterTap,
- ),
- ));
- }
- if (showRight && rightLabel != null) {
- addGap();
- buttons.add(Expanded(
- child: _ActionButton(
- label: rightLabel!,
- backgroundColor: colors.primary,
- textColor: colors.bgCard,
- onTap: onRightTap,
- ),
- ));
- }
- return buttons;
- }
- }
- class _ActionButton extends StatelessWidget {
- final String label;
- final Color backgroundColor;
- final Color textColor;
- final VoidCallback? onTap;
- const _ActionButton({
- required this.label,
- required this.backgroundColor,
- required this.textColor,
- this.onTap,
- });
- @override
- Widget build(BuildContext context) {
- return SizedBox(
- height: 40,
- child: Material(
- color: backgroundColor,
- borderRadius: BorderRadius.circular(22),
- child: InkWell(
- onTap: onTap,
- borderRadius: BorderRadius.circular(22),
- child: Center(
- child: Text(
- label,
- style: TextStyle(
- fontSize: AppFontSizes.body,
- fontWeight: FontWeight.w500,
- color: textColor,
- ),
- ),
- ),
- ),
- ),
- );
- }
- }
|