fix(client): 打印异常加 try-catch,错误以 SnackBar 提示用户

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-05-25 20:41:15 +08:00
parent 93878511e5
commit 44ffedb56a
3 changed files with 57 additions and 9 deletions
@@ -247,8 +247,16 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
),
TextButton(
onPressed: () async {
final order = await ref.read(stockInRepositoryProvider).get(o.id);
await printStockInOrder(order);
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),
);
}
}
},
child: const Text('打印',
style: TextStyle(fontSize: 12, color: AppTheme.primary)),
@@ -690,7 +698,17 @@ class _StockInDetailDialogState extends ConsumerState<_StockInDetailDialog> {
IconButton(
icon: const Icon(Icons.print_outlined, color: Colors.white),
tooltip: '打印',
onPressed: () => printStockInOrder(_loadedOrder!),
onPressed: () async {
try {
await printStockInOrder(_loadedOrder!);
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString()), backgroundColor: Colors.red),
);
}
}
},
),
IconButton(
icon: const Icon(Icons.close, color: Colors.white),
@@ -254,8 +254,16 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
),
TextButton(
onPressed: () async {
final order = await ref.read(stockOutRepositoryProvider).get(o.id);
await printStockOutOrder(order);
try {
final order = await ref.read(stockOutRepositoryProvider).get(o.id);
await printStockOutOrder(order);
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString()), backgroundColor: Colors.red),
);
}
}
},
child: const Text('打印',
style: TextStyle(fontSize: 12, color: AppTheme.primary)),
@@ -682,7 +690,17 @@ class _StockOutDetailDialogState extends ConsumerState<_StockOutDetailDialog> {
IconButton(
icon: const Icon(Icons.print_outlined, color: Colors.white),
tooltip: '打印',
onPressed: () => printStockOutOrder(_loadedOrder!),
onPressed: () async {
try {
await printStockOutOrder(_loadedOrder!);
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString()), backgroundColor: Colors.red),
);
}
}
},
),
IconButton(
icon: const Icon(Icons.close, color: Colors.white),