From e52dbee8358ab3d7a8e50ca948210f52b8debe8b Mon Sep 17 00:00:00 2001 From: Mark M2 Macbook Date: Mon, 11 May 2026 18:19:48 +0200 Subject: [PATCH] mmm --- .../tickets/utils/ticket_pdf_service.dart | 44 ++++++++++--------- pubspec.yaml | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/features/tickets/utils/ticket_pdf_service.dart b/lib/features/tickets/utils/ticket_pdf_service.dart index 4045d5f..c635bf2 100644 --- a/lib/features/tickets/utils/ticket_pdf_service.dart +++ b/lib/features/tickets/utils/ticket_pdf_service.dart @@ -17,21 +17,31 @@ class TicketPdfService { final font = await PdfGoogleFonts.robotoRegular(); final boldFont = await PdfGoogleFonts.robotoBold(); + pw.Widget customerHalf = await _buildTicketHalf( + ticket, + company, + font, + boldFont, + isForCustomer: true, + ); + + pw.Widget storeHalf = await _buildTicketHalf( + ticket, + company, + font, + boldFont, + isForCustomer: false, + ); + pdf.addPage( pw.Page( pageFormat: PdfPageFormat.a4, margin: const pw.EdgeInsets.all(20), - build: (context) { + build: (pw.Context context) { return pw.Column( children: [ // 1. METÀ SUPERIORE: CLIENTE - _buildTicketHalf( - ticket, - company, - font, - boldFont, - isForCustomer: true, - ), + customerHalf, pw.SizedBox(height: 10), @@ -47,32 +57,26 @@ class TicketPdfService { pw.SizedBox(height: 10), // 2. METÀ INFERIORE: NEGOZIO - _buildTicketHalf( - ticket, - company, - font, - boldFont, - isForCustomer: false, - ), + storeHalf, ], ); }, ), ); - await Printing.layoutPdf( - onLayout: (PdfPageFormat format) async => pdf.save(), - ); + final savedPdf = await pdf.save(); + + await Printing.layoutPdf(onLayout: (PdfPageFormat format) => savedPdf); } /// Helper per costruire una singola metà (Cliente o Negozio) - pw.Widget _buildTicketHalf( + Future _buildTicketHalf( TicketModel ticket, CompanyModel company, pw.Font font, pw.Font boldFont, { required bool isForCustomer, - }) { + }) async { return pw.Expanded( //height: 380, // Circa metà A4 meno i margini child: pw.Column( diff --git a/pubspec.yaml b/pubspec.yaml index 1c40f76..2d3071c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: uuid: ^4.5.3 pdf: ^3.12.0 universal_io: ^2.3.1 - printing: ^5.14.3 + printing: ^5.13.1 dev_dependencies: flutter_test: