109 lines
3.6 KiB
Dart
109 lines
3.6 KiB
Dart
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:forui/forui.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
enum TerminalToolbarButtonStyle { primary, secondary, danger }
|
|
|
|
/// 统一搜索、重置、删除、扫码等工具操作的高度,避免主题尺寸变化后相邻控件错位。
|
|
class TerminalToolbarButton extends StatelessWidget {
|
|
const TerminalToolbarButton({
|
|
super.key,
|
|
required this.label,
|
|
required this.onTap,
|
|
this.icon,
|
|
this.style = TerminalToolbarButtonStyle.primary,
|
|
this.minWidth,
|
|
});
|
|
|
|
final String label;
|
|
final VoidCallback? onTap;
|
|
final SvgAsset? icon;
|
|
final TerminalToolbarButtonStyle style;
|
|
final double? minWidth;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = FTheme.of(context);
|
|
final enabled = onTap != null;
|
|
final background = switch (style) {
|
|
TerminalToolbarButtonStyle.primary => XfjDesignTokens.primary,
|
|
TerminalToolbarButtonStyle.secondary => XfjDesignTokens.surface,
|
|
TerminalToolbarButtonStyle.danger => const Color(0xFFFFF3F2),
|
|
};
|
|
final foreground = switch (style) {
|
|
TerminalToolbarButtonStyle.primary => Colors.white,
|
|
TerminalToolbarButtonStyle.secondary => XfjDesignTokens.ink,
|
|
TerminalToolbarButtonStyle.danger => XfjDesignTokens.danger,
|
|
};
|
|
final border = switch (style) {
|
|
TerminalToolbarButtonStyle.primary => XfjDesignTokens.primary,
|
|
TerminalToolbarButtonStyle.secondary => XfjDesignTokens.line,
|
|
TerminalToolbarButtonStyle.danger =>
|
|
XfjDesignTokens.danger.withValues(alpha: 0.35),
|
|
};
|
|
return Opacity(
|
|
opacity: enabled ? 1 : 0.45,
|
|
child: Material(
|
|
color: background,
|
|
borderRadius: BorderRadius.circular(XfjDesignTokens.controlRadius),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(XfjDesignTokens.controlRadius),
|
|
child: Container(
|
|
height: XfjDesignTokens.controlHeight.h,
|
|
constraints: BoxConstraints(minWidth: minWidth ?? 92.w),
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 18.w * XfjDesignTokens.buttonSizeScale,
|
|
),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: border),
|
|
borderRadius:
|
|
BorderRadius.circular(XfjDesignTokens.controlRadius),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
if (icon != null) ...[
|
|
FIcon(icon!, size: 19.sp, color: foreground),
|
|
SizedBox(width: 8.w),
|
|
],
|
|
Flexible(
|
|
child: Text(
|
|
label,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: theme.typography.base.copyWith(
|
|
color: foreground,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 给输入框、时间和餐段选择器提供与按钮一致的外部高度约束。
|
|
class TerminalToolbarControl extends StatelessWidget {
|
|
const TerminalToolbarControl({super.key, required this.child, this.width});
|
|
|
|
final Widget child;
|
|
final double? width;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: width,
|
|
height: XfjDesignTokens.controlHeight.h,
|
|
child: child,
|
|
);
|
|
}
|
|
}
|