mmm
This commit is contained in:
@@ -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();
|
||||||
|
|
||||||
|
pw.Widget customerHalf = await _buildTicketHalf(
|
||||||
|
ticket,
|
||||||
|
company,
|
||||||
|
font,
|
||||||
|
boldFont,
|
||||||
|
isForCustomer: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
pw.Widget storeHalf = await _buildTicketHalf(
|
||||||
|
ticket,
|
||||||
|
company,
|
||||||
|
font,
|
||||||
|
boldFont,
|
||||||
|
isForCustomer: false,
|
||||||
|
);
|
||||||
|
|
||||||
pdf.addPage(
|
pdf.addPage(
|
||||||
pw.Page(
|
pw.Page(
|
||||||
pageFormat: PdfPageFormat.a4,
|
pageFormat: PdfPageFormat.a4,
|
||||||
margin: const pw.EdgeInsets.all(20),
|
margin: const pw.EdgeInsets.all(20),
|
||||||
build: (context) {
|
build: (pw.Context context) {
|
||||||
return pw.Column(
|
return pw.Column(
|
||||||
children: [
|
children: [
|
||||||
// 1. METÀ SUPERIORE: CLIENTE
|
// 1. METÀ SUPERIORE: CLIENTE
|
||||||
_buildTicketHalf(
|
customerHalf,
|
||||||
ticket,
|
|
||||||
company,
|
|
||||||
font,
|
|
||||||
boldFont,
|
|
||||||
isForCustomer: true,
|
|
||||||
),
|
|
||||||
|
|
||||||
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(
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user