320 lines
11 KiB
Dart
320 lines
11 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,
|
|
destructive,
|
|
}
|
|
|
|
/// 统一搜索、重置、删除、扫码等工具操作的高度,避免主题尺寸变化后相邻控件错位。
|
|
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),
|
|
TerminalToolbarButtonStyle.destructive => XfjDesignTokens.danger,
|
|
};
|
|
final foreground = switch (style) {
|
|
TerminalToolbarButtonStyle.primary => Colors.white,
|
|
TerminalToolbarButtonStyle.secondary => XfjDesignTokens.ink,
|
|
TerminalToolbarButtonStyle.danger => XfjDesignTokens.danger,
|
|
TerminalToolbarButtonStyle.destructive => Colors.white,
|
|
};
|
|
final border = switch (style) {
|
|
TerminalToolbarButtonStyle.primary => XfjDesignTokens.primary,
|
|
TerminalToolbarButtonStyle.secondary => XfjDesignTokens.line,
|
|
TerminalToolbarButtonStyle.danger =>
|
|
XfjDesignTokens.danger.withValues(alpha: 0.35),
|
|
TerminalToolbarButtonStyle.destructive => XfjDesignTokens.danger,
|
|
};
|
|
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,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 终端工具栏统一单行输入框。
|
|
///
|
|
/// Forui 的普通单行输入框会按文字自然高度布局,即使外层工具栏已经等高,边框仍可能
|
|
/// 比按钮更矮;这里统一收敛组件结构和局部主题,让所有工具栏输入框共享同一尺寸规则。
|
|
class TerminalToolbarTextField extends StatelessWidget {
|
|
/// 创建由页面持有输入状态、由公共组件负责尺寸和主题适配的工具栏输入框。
|
|
const TerminalToolbarTextField({
|
|
super.key,
|
|
required this.controller,
|
|
required this.hint,
|
|
this.width,
|
|
this.focusNode,
|
|
this.textInputAction,
|
|
this.keyboardType,
|
|
this.onSubmit,
|
|
this.prefixBuilder,
|
|
this.softKeyboard,
|
|
this.softKeyboardAllowPattern,
|
|
this.softKeyboardMaxLength,
|
|
});
|
|
|
|
final double? width;
|
|
|
|
/// 页面持有的文本控制器,公共组件不接管其生命周期。
|
|
final TextEditingController controller;
|
|
|
|
/// 页面持有的焦点节点;为空时沿用 Forui 的内部焦点管理。
|
|
final FocusNode? focusNode;
|
|
|
|
/// 无输入内容时展示的业务提示。
|
|
final String hint;
|
|
|
|
/// 软键盘动作类型;硬件输入场景可继续传入现有配置。
|
|
final TextInputAction? textInputAction;
|
|
|
|
/// 输入键盘类型;收银扫码等场景可传入 [TextInputType.none] 禁止弹出软键盘。
|
|
final TextInputType? keyboardType;
|
|
|
|
/// 用户提交输入时的页面回调,组件本身不触发查询副作用。
|
|
final ValueChanged<String>? onSubmit;
|
|
|
|
/// 输入框前缀构建器,用于页面已有的搜索图标等语义提示。
|
|
final ValueWidgetBuilder<FTextFieldStateStyle>? prefixBuilder;
|
|
|
|
/// 启用自研软键盘的初始面板;为空时不接管点击(保持现状)。
|
|
///
|
|
/// 启用后输入框抑制系统软键盘并改为弹出 [AppSoftKeyboard];实体键盘与
|
|
/// 扫码枪的物理按键输入不受影响。
|
|
final AppSoftKeyboardMode? softKeyboard;
|
|
|
|
/// 自研键盘的可插入字符白名单;为空时不限制。
|
|
final RegExp? softKeyboardAllowPattern;
|
|
|
|
/// 自研键盘的文本长度上限;为空时不限制。
|
|
final int? softKeyboardMaxLength;
|
|
|
|
/// 构建随按钮大小档位变化的单行输入框。
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final keyboardMode = softKeyboard;
|
|
return TerminalToolbarControl(
|
|
width: width,
|
|
child: FTextField(
|
|
controller: controller,
|
|
focusNode: focusNode,
|
|
hint: hint,
|
|
textInputAction: textInputAction,
|
|
// 自研键盘接管时抑制系统软键盘,只保留物理按键输入通道。
|
|
keyboardType: keyboardMode != null ? TextInputType.none : keyboardType,
|
|
maxLines: 1,
|
|
onSubmit: onSubmit,
|
|
prefixBuilder: prefixBuilder,
|
|
onTap: keyboardMode == null
|
|
? null
|
|
: () => AppSoftKeyboard.show(
|
|
context,
|
|
controller: controller,
|
|
mode: keyboardMode,
|
|
allowPattern: softKeyboardAllowPattern,
|
|
maxLength: softKeyboardMaxLength,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 给工具栏输入框提供与搜索、重置按钮一致的确定高度。
|
|
///
|
|
/// 高度统一取自 [XfjDesignTokens.controlHeight],因此会随基本设置中的按钮大小档位
|
|
/// 一起变化;局部主题同时收敛 Forui 内边距,避免大字号终端出现内容溢出。
|
|
class TerminalToolbarControl extends StatelessWidget {
|
|
/// 创建负责约束工具栏控件尺寸和局部输入主题的容器。
|
|
const TerminalToolbarControl({super.key, required this.child, this.width});
|
|
|
|
/// 需要与工具栏按钮对齐的输入控件。
|
|
final Widget child;
|
|
|
|
/// 控件宽度;为空时由父级布局分配可用宽度。
|
|
final double? width;
|
|
|
|
/// 根据当前字体与按钮档位计算输入内边距,保证实际边框高度等于按钮高度。
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = FTheme.of(context);
|
|
final controlHeight = XfjDesignTokens.controlHeight.h;
|
|
final textPainter = TextPainter(
|
|
text: TextSpan(
|
|
text: '国Hg',
|
|
style: theme.textFieldStyle.enabledStyle.contentTextStyle,
|
|
),
|
|
maxLines: 1,
|
|
textDirection: Directionality.of(context),
|
|
textScaler: MediaQuery.textScalerOf(context),
|
|
)..layout();
|
|
// Forui 单行输入框的绘制高度由文字行高和上下内边距组成,按运行时字体反算
|
|
// 内边距后,字体大小和按钮大小可独立变化且不会再次造成控件错位。
|
|
final verticalPadding = ((controlHeight - textPainter.height) / 2)
|
|
.clamp(0.0, controlHeight / 2);
|
|
textPainter.dispose();
|
|
return FTheme(
|
|
// Forui 0.9.1+1 的默认输入内边距是未适配的逻辑像素,工具栏内需按终端比例收敛。
|
|
data: theme.copyWith(
|
|
textFieldStyle: theme.textFieldStyle.copyWith(
|
|
contentPadding: EdgeInsets.symmetric(
|
|
horizontal: 14.w,
|
|
vertical: verticalPadding,
|
|
),
|
|
),
|
|
),
|
|
child: SizedBox(
|
|
width: width,
|
|
height: controlHeight,
|
|
child: child,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 终端工具栏日期范围控件,统一处理紧凑横屏下的完整日期展示。
|
|
class TerminalToolbarDateControl extends StatelessWidget {
|
|
const TerminalToolbarDateControl({
|
|
super.key,
|
|
required this.label,
|
|
required this.onTap,
|
|
this.width,
|
|
this.showChevron = false,
|
|
this.textStyle,
|
|
});
|
|
|
|
final String label;
|
|
final VoidCallback onTap;
|
|
final double? width;
|
|
final bool showChevron;
|
|
final TextStyle? textStyle;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = FTheme.of(context);
|
|
return SizedBox(
|
|
width: width,
|
|
child: Semantics(
|
|
button: true,
|
|
label: '日期范围:$label',
|
|
child: Material(
|
|
color: XfjDesignTokens.surface,
|
|
clipBehavior: Clip.antiAlias,
|
|
shape: RoundedRectangleBorder(
|
|
side: const BorderSide(color: XfjDesignTokens.line),
|
|
borderRadius: BorderRadius.circular(
|
|
XfjDesignTokens.controlRadius,
|
|
),
|
|
),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
minHeight: XfjDesignTokens.controlHeight.h,
|
|
),
|
|
child: <Widget>[
|
|
FIcon(
|
|
FAssets.icons.calendar,
|
|
size: 19.sp,
|
|
color: XfjDesignTokens.ink,
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
// 日期文本只在空间不足时轻微缩小,避免省略结束日期或触发横向溢出。
|
|
child: FittedBox(
|
|
fit: BoxFit.scaleDown,
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
label,
|
|
maxLines: 1,
|
|
style: textStyle ??
|
|
theme.typography.base.copyWith(
|
|
color: XfjDesignTokens.ink,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (showChevron) ...[
|
|
SizedBox(width: 8.w),
|
|
FIcon(
|
|
FAssets.icons.chevronsUpDown,
|
|
size: 16.sp,
|
|
color: XfjDesignTokens.muted,
|
|
),
|
|
],
|
|
]
|
|
.toRow(crossAxisAlignment: CrossAxisAlignment.center)
|
|
.padding(horizontal: 12.w),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|