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 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 renderLabelPreview(LabelData label) => renderLabelPreviewImpl(label); /// 枚举当前系统所有可用打印机名;Web 平台返回空列表。 Future> listLabelPrinters() => listLabelPrintersImpl(); /// 自动检测默认热敏打印机(名字含 deli/dl-888);找不到或 Web 返回 null。 Future detectDefaultPrinter() => detectDefaultPrinterImpl(); Future printStockInOrder(StockInOrder order) => printStockInOrderImpl(order); Future printStockOutOrder(StockOutOrder order) => printStockOutOrderImpl(order); /// 统一打印入口:catch 任意异常,上报并弹 SnackBar 给用户。 /// 用法:await safePrint(context, () => printStockInOrder(order)); Future safePrint(BuildContext context, Future 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), ); } } }