104b98f4ac
- 新增 LabelData 模型统一聚合单张标签字段(qrBytes/copies 等) - 抽取 _renderLabelBitmap 共享位图绘制逻辑,TSPL 裸发与预览渲染完全一致 - 新增 renderLabelPreview / listLabelPrinters / detectDefaultPrinter 公开 API - printProductLabel 新增 printerName 参数,透传到热敏裸发路径 - 新建 LabelPreviewDialog:缩略图条+大图主视图,打印机下拉+记忆(SharedPrefs) 份数调整、勾选跳过、逐张打印进度状态显示 - 库存/商品详情/入库单 打标签 均接入预览弹窗,移除旧 _LabelPrintDialog Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
70 lines
2.1 KiB
Dart
70 lines
2.1 KiB
Dart
import 'dart:typed_data';
|
|
import 'package:flutter/material.dart';
|
|
import '../../models/stock_in.dart';
|
|
import '../../models/stock_out.dart';
|
|
import '../errors/error_reporter.dart';
|
|
import 'label_data.dart';
|
|
export 'label_data.dart';
|
|
import 'print_util_stub.dart'
|
|
if (dart.library.js_interop) 'print_util_web.dart';
|
|
|
|
Future<void> printProductLabel({
|
|
required Uint8List qrBytes,
|
|
required String name,
|
|
required String code,
|
|
String? spec,
|
|
String? series,
|
|
String? batchNo,
|
|
String? productionDate,
|
|
String? remark,
|
|
String shopName = '',
|
|
String shopAddress = '',
|
|
String shopPhone = '',
|
|
String? printerName,
|
|
}) =>
|
|
printProductLabelImpl(
|
|
qrBytes: qrBytes,
|
|
name: name,
|
|
code: code,
|
|
spec: spec,
|
|
series: series,
|
|
batchNo: batchNo,
|
|
productionDate: productionDate,
|
|
remark: remark,
|
|
shopName: shopName,
|
|
shopAddress: shopAddress,
|
|
shopPhone: shopPhone,
|
|
printerName: printerName,
|
|
);
|
|
|
|
/// 渲染标签预览图(PNG 字节);Web 平台返回 null。
|
|
Future<Uint8List?> renderLabelPreview(LabelData label) =>
|
|
renderLabelPreviewImpl(label);
|
|
|
|
/// 枚举当前系统所有可用打印机名;Web 平台返回空列表。
|
|
Future<List<String>> listLabelPrinters() => listLabelPrintersImpl();
|
|
|
|
/// 自动检测默认热敏打印机(名字含 deli/dl-888);找不到或 Web 返回 null。
|
|
Future<String?> detectDefaultPrinter() => detectDefaultPrinterImpl();
|
|
|
|
Future<void> printStockInOrder(StockInOrder order) =>
|
|
printStockInOrderImpl(order);
|
|
|
|
Future<void> printStockOutOrder(StockOutOrder order) =>
|
|
printStockOutOrderImpl(order);
|
|
|
|
/// 统一打印入口:catch 任意异常,上报并弹 SnackBar 给用户。
|
|
/// 用法:await safePrint(context, () => printStockInOrder(order));
|
|
Future<void> safePrint(BuildContext context, Future<void> Function() fn) async {
|
|
try {
|
|
await fn();
|
|
} catch (e, st) {
|
|
reportError(e, st);
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('打印失败:$e'), backgroundColor: Colors.red),
|
|
);
|
|
}
|
|
}
|
|
}
|