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 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<pw.Widget> _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(

View File

@@ -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: