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
@@ -485,12 +485,12 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
item.productId != null
? TextButton(
onPressed: () async {
try {
final qrBytes = await ref
.read(productRepositoryProvider)
.getQRCodeBytes(item.productId!);
final shopInfo = ref.read(shopInfoProvider).valueOrNull;
await printProductLabel(
final qrBytes = await ref
.read(productRepositoryProvider)
.getQRCodeBytes(item.productId!);
final shopInfo = ref.read(shopInfoProvider).valueOrNull;
if (context.mounted) {
await safePrint(context, () => printProductLabel(
qrBytes: qrBytes,
name: item.productName,
code: item.productCode,
@@ -502,14 +502,7 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
shopName: shopInfo?.name ?? '',
shopAddress: shopInfo?.address ?? '',
shopPhone: shopInfo?.phone ?? '',
);
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('打印失败:$e'),
backgroundColor: AppTheme.danger),
);
}
));
}
},
child: const Text('打标签',