fix(client): 统一打印错误处理,失败时上报并弹提示
新增 safePrint 封装,所有打印调用点统一 catch 任意异常(含字体加载失败), 自动上报 error_reporter 并展示 SnackBar,不再静默失败。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
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 'print_util_stub.dart'
|
||||
if (dart.library.js_interop) 'print_util_web.dart';
|
||||
|
||||
@@ -36,3 +38,18 @@ Future<void> printStockInOrder(StockInOrder 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),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,6 @@ Future<void> printProductLabelImpl({
|
||||
),
|
||||
));
|
||||
|
||||
try {
|
||||
await Printing.layoutPdf(onLayout: (_) async => doc.save());
|
||||
} catch (e, st) {
|
||||
reportError(e, st);
|
||||
@@ -430,7 +429,6 @@ Future<void> printStockInOrderImpl(StockInOrder order) async {
|
||||
),
|
||||
],
|
||||
));
|
||||
try {
|
||||
await Printing.layoutPdf(onLayout: (_) async => doc.save());
|
||||
} catch (e, st) {
|
||||
reportError(e, st);
|
||||
|
||||
Reference in New Issue
Block a user