fix(client): 统一打印错误处理,失败时上报并弹提示
新增 safePrint 封装,所有打印调用点统一 catch 任意异常(含字体加载失败), 自动上报 error_reporter 并展示 SnackBar,不再静默失败。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -137,7 +137,7 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
|
||||
|
||||
Future<void> _printOrder() async {
|
||||
if (_loadedOrder == null) return;
|
||||
await printStockInOrder(_loadedOrder!);
|
||||
await safePrint(context, () => printStockInOrder(_loadedOrder!));
|
||||
}
|
||||
|
||||
Future<void> _submit(bool asDraft) async {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import '../../core/utils/dialog_util.dart';
|
||||
import '../../core/errors/error_reporter.dart';
|
||||
import '../../core/utils/print_util.dart' show safePrint, printStockInOrder, printProductLabel;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -247,15 +249,9 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
try {
|
||||
final order = await ref.read(stockInRepositoryProvider).get(o.id);
|
||||
await printStockInOrder(order);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString()), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
final order = await ref.read(stockInRepositoryProvider).get(o.id);
|
||||
if (context.mounted) {
|
||||
await safePrint(context, () => printStockInOrder(order));
|
||||
}
|
||||
},
|
||||
child: const Text('打印',
|
||||
@@ -698,17 +694,7 @@ class _StockInDetailDialogState extends ConsumerState<_StockInDetailDialog> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.print_outlined, color: Colors.white),
|
||||
tooltip: '打印',
|
||||
onPressed: () async {
|
||||
try {
|
||||
await printStockInOrder(_loadedOrder!);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString()), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
onPressed: () => safePrint(context, () => printStockInOrder(_loadedOrder!)),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
@@ -966,7 +952,8 @@ class _LabelPrintDialogState extends State<_LabelPrintDialog> {
|
||||
);
|
||||
done++;
|
||||
if (mounted) setState(() => _status = '已打印 $done 张...');
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
reportError(e, st);
|
||||
if (mounted) setState(() => _status = '第${i + 1}行打印失败:$e');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user