fix(client): 统一打印错误处理,失败时上报并弹提示

新增 safePrint 封装,所有打印调用点统一 catch 任意异常(含字体加载失败),
自动上报 error_reporter 并展示 SnackBar,不再静默失败。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-05-25 22:55:56 +08:00
parent b6223b3816
commit 3d1fc0d4ba
10 changed files with 58 additions and 77 deletions
@@ -528,10 +528,10 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
Future<void> _print() async {
if (_bytes == null || _printing) return;
setState(() { _printing = true; _printStatus = '正在打印...'; });
final p = widget.product;
final shopInfo = ref.read(shopInfoProvider).valueOrNull;
try {
final p = widget.product;
final shopInfo = ref.read(shopInfoProvider).valueOrNull;
await printProductLabel(
await safePrint(context, () => printProductLabel(
qrBytes: _bytes!,
name: p.name,
code: p.code,
@@ -540,13 +540,7 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
shopName: shopInfo?.name ?? '',
shopAddress: shopInfo?.address ?? '',
shopPhone: shopInfo?.phone ?? '',
);
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('打印失败:$e'), backgroundColor: Colors.red),
);
}
));
} finally {
if (mounted) setState(() { _printing = false; _printStatus = ''; });
}