This commit is contained in:
2026-05-11 18:19:48 +02:00
parent 1dee51a7cd
commit e52dbee835
2 changed files with 25 additions and 21 deletions

View File

@@ -17,21 +17,31 @@ class TicketPdfService {
final font = await PdfGoogleFonts.robotoRegular(); final font = await PdfGoogleFonts.robotoRegular();
final boldFont = await PdfGoogleFonts.robotoBold(); final boldFont = await PdfGoogleFonts.robotoBold();
pdf.addPage( pw.Widget customerHalf = await _buildTicketHalf(
pw.Page(
pageFormat: PdfPageFormat.a4,
margin: const pw.EdgeInsets.all(20),
build: (context) {
return pw.Column(
children: [
// 1. METÀ SUPERIORE: CLIENTE
_buildTicketHalf(
ticket, ticket,
company, company,
font, font,
boldFont, boldFont,
isForCustomer: true, 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: (pw.Context context) {
return pw.Column(
children: [
// 1. METÀ SUPERIORE: CLIENTE
customerHalf,
pw.SizedBox(height: 10), pw.SizedBox(height: 10),
@@ -47,32 +57,26 @@ class TicketPdfService {
pw.SizedBox(height: 10), pw.SizedBox(height: 10),
// 2. METÀ INFERIORE: NEGOZIO // 2. METÀ INFERIORE: NEGOZIO
_buildTicketHalf( storeHalf,
ticket,
company,
font,
boldFont,
isForCustomer: false,
),
], ],
); );
}, },
), ),
); );
await Printing.layoutPdf( final savedPdf = await pdf.save();
onLayout: (PdfPageFormat format) async => pdf.save(),
); await Printing.layoutPdf(onLayout: (PdfPageFormat format) => savedPdf);
} }
/// Helper per costruire una singola metà (Cliente o Negozio) /// Helper per costruire una singola metà (Cliente o Negozio)
pw.Widget _buildTicketHalf( Future<pw.Widget> _buildTicketHalf(
TicketModel ticket, TicketModel ticket,
CompanyModel company, CompanyModel company,
pw.Font font, pw.Font font,
pw.Font boldFont, { pw.Font boldFont, {
required bool isForCustomer, required bool isForCustomer,
}) { }) async {
return pw.Expanded( return pw.Expanded(
//height: 380, // Circa metà A4 meno i margini //height: 380, // Circa metà A4 meno i margini
child: pw.Column( child: pw.Column(

View File

@@ -33,7 +33,7 @@ dependencies:
uuid: ^4.5.3 uuid: ^4.5.3
pdf: ^3.12.0 pdf: ^3.12.0
universal_io: ^2.3.1 universal_io: ^2.3.1
printing: ^5.14.3 printing: ^5.13.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: