diff --git a/client/lib/core/utils/print_util_stub.dart b/client/lib/core/utils/print_util_stub.dart index cf1428f..2a6b7e8 100644 --- a/client/lib/core/utils/print_util_stub.dart +++ b/client/lib/core/utils/print_util_stub.dart @@ -189,7 +189,11 @@ Future printProductLabelImpl({ ), )); - await Printing.layoutPdf(onLayout: (_) async => doc.save()); + try { + await Printing.layoutPdf(onLayout: (_) async => doc.save()); + } catch (e) { + throw Exception('打印失败,请检查打印机连接和驱动是否正常。\n详情:$e'); + } } pw.Widget _label2ColRow( @@ -424,7 +428,11 @@ Future printStockInOrderImpl(StockInOrder order) async { ), ], )); - await Printing.layoutPdf(onLayout: (_) async => doc.save()); + try { + await Printing.layoutPdf(onLayout: (_) async => doc.save()); + } catch (e) { + throw Exception('打印失败,请检查打印机连接和驱动是否正常。\n详情:$e'); + } } Future printStockOutOrderImpl(StockOutOrder order) async { @@ -474,5 +482,9 @@ Future printStockOutOrderImpl(StockOutOrder order) async { ), ], )); - await Printing.layoutPdf(onLayout: (_) async => doc.save()); + try { + await Printing.layoutPdf(onLayout: (_) async => doc.save()); + } catch (e) { + throw Exception('打印失败,请检查打印机连接和驱动是否正常。\n详情:$e'); + } } diff --git a/client/lib/screens/stock_in/stock_in_list_screen.dart b/client/lib/screens/stock_in/stock_in_list_screen.dart index 5b9450a..5c9a355 100644 --- a/client/lib/screens/stock_in/stock_in_list_screen.dart +++ b/client/lib/screens/stock_in/stock_in_list_screen.dart @@ -247,8 +247,16 @@ class _StockInListScreenState extends ConsumerState { ), 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), diff --git a/client/lib/screens/stock_out/stock_out_list_screen.dart b/client/lib/screens/stock_out/stock_out_list_screen.dart index a17e669..7b44e23 100644 --- a/client/lib/screens/stock_out/stock_out_list_screen.dart +++ b/client/lib/screens/stock_out/stock_out_list_screen.dart @@ -254,8 +254,16 @@ class _StockOutListScreenState extends ConsumerState { ), 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),