Browse Source

impression

master
Stephane 4 months ago
parent
commit
1207eeff13
  1. 86
      lib/services/pdf_service.dart

86
lib/services/pdf_service.dart

@ -71,12 +71,18 @@ class PlatformPrintService {
pdf.addPage( pdf.addPage(
pw.Page( pw.Page(
pageFormat: ticket58mmFormat, pageFormat: ticket58mmFormat,
margin: const pw.EdgeInsets.all(2), // 🔧 Marges minimales
build: (pw.Context context) { build: (pw.Context context) {
return pw.Column( return pw.Container(
crossAxisAlignment: pw.CrossAxisAlignment.center, width: double.infinity, // 🔧 Forcer la largeur complète
child: pw.Column(
crossAxisAlignment:
pw.CrossAxisAlignment.start, // 🔧 Alignement à gauche
children: [ children: [
// En-tête Restaurant (centré et compact) // En-tête Restaurant (centré et compact)
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
restaurantInfo['nom']!, restaurantInfo['nom']!,
style: pw.TextStyle( style: pw.TextStyle(
fontSize: titleSize, fontSize: titleSize,
@ -84,26 +90,36 @@ class PlatformPrintService {
), ),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.SizedBox(height: 1), pw.SizedBox(height: 1),
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
restaurantInfo['adresse']!, restaurantInfo['adresse']!,
style: pw.TextStyle(fontSize: smallSize), style: pw.TextStyle(fontSize: smallSize),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
restaurantInfo['ville']!, restaurantInfo['ville']!,
style: pw.TextStyle(fontSize: smallSize), style: pw.TextStyle(fontSize: smallSize),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
'Tel: ${restaurantInfo['contact']!}', 'Tel: ${restaurantInfo['contact']!}',
style: pw.TextStyle(fontSize: smallSize), style: pw.TextStyle(fontSize: smallSize),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.SizedBox(height: 3), pw.SizedBox(height: 3),
@ -117,7 +133,9 @@ class PlatformPrintService {
pw.SizedBox(height: 2), pw.SizedBox(height: 2),
// Informations ticket // Informations ticket
pw.Row( pw.Container(
width: double.infinity,
child: pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [ children: [
pw.Text( pw.Text(
@ -127,16 +145,15 @@ class PlatformPrintService {
fontWeight: pw.FontWeight.bold, fontWeight: pw.FontWeight.bold,
), ),
), ),
pw.Text(
'Via: ${commande.tablename ?? 'Table inconnue'}',
style: pw.TextStyle(fontSize: bodySize),
),
], ],
), ),
),
pw.SizedBox(height: 1), pw.SizedBox(height: 1),
pw.Row( pw.Container(
width: double.infinity,
child: pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [ children: [
pw.Text( pw.Text(
@ -149,6 +166,7 @@ class PlatformPrintService {
), ),
], ],
), ),
),
pw.SizedBox(height: 2), pw.SizedBox(height: 2),
@ -165,19 +183,25 @@ class PlatformPrintService {
...commande.items ...commande.items
.map( .map(
(item) => pw.Container( (item) => pw.Container(
width: double.infinity, // 🔧 Largeur complète
margin: const pw.EdgeInsets.only(bottom: 1), margin: const pw.EdgeInsets.only(bottom: 1),
child: pw.Column( child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start, crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [ children: [
// Nom du plat // Nom du plat
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
'${item.menuNom}', '${item.menuNom}',
style: pw.TextStyle(fontSize: bodySize), style: pw.TextStyle(fontSize: bodySize),
maxLines: 2, maxLines: 2,
), ),
),
// Quantité, prix unitaire et total sur une ligne // Quantité, prix unitaire et total sur une ligne
pw.Row( pw.Container(
width: double.infinity,
child: pw.Row(
mainAxisAlignment: mainAxisAlignment:
pw.MainAxisAlignment.spaceBetween, pw.MainAxisAlignment.spaceBetween,
children: [ children: [
@ -194,6 +218,7 @@ class PlatformPrintService {
), ),
], ],
), ),
),
], ],
), ),
), ),
@ -212,7 +237,9 @@ class PlatformPrintService {
pw.SizedBox(height: 2), pw.SizedBox(height: 2),
// Total // Total
pw.Row( pw.Container(
width: double.infinity,
child: pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [ children: [
pw.Text( pw.Text(
@ -231,15 +258,19 @@ class PlatformPrintService {
), ),
], ],
), ),
),
pw.SizedBox(height: 3), pw.SizedBox(height: 3),
// Mode de paiement // Mode de paiement
pw.Text( pw.Container(
'Paiement: ${_getPaymentMethodText(paymentMethod)}', width: double.infinity,
child: pw.Text(
'Paiement: ${paymentMethod.toLowerCase()}',
style: pw.TextStyle(fontSize: bodySize), style: pw.TextStyle(fontSize: bodySize),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.SizedBox(height: 3), pw.SizedBox(height: 3),
@ -253,7 +284,9 @@ class PlatformPrintService {
pw.SizedBox(height: 2), pw.SizedBox(height: 2),
// Message de remerciement // Message de remerciement
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
'Merci de votre visite !', 'Merci de votre visite !',
style: pw.TextStyle( style: pw.TextStyle(
fontSize: bodySize, fontSize: bodySize,
@ -261,33 +294,44 @@ class PlatformPrintService {
), ),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
'A bientôt !', 'A bientôt !',
style: pw.TextStyle(fontSize: smallSize), style: pw.TextStyle(fontSize: smallSize),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.SizedBox(height: 3), pw.SizedBox(height: 3),
// Code de suivi (optionnel) // Code de suivi (optionnel)
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
'Code: ${factureNumber}', 'Code: ${factureNumber}',
style: pw.TextStyle(fontSize: smallSize), style: pw.TextStyle(fontSize: smallSize),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.SizedBox(height: 4), pw.SizedBox(height: 4),
// Ligne de découpe // Ligne de découpe
pw.Text( pw.Container(
width: double.infinity,
child: pw.Text(
'- - - - - - - - - - - - - - - -', '- - - - - - - - - - - - - - - -',
style: pw.TextStyle(fontSize: smallSize), style: pw.TextStyle(fontSize: smallSize),
textAlign: pw.TextAlign.center, textAlign: pw.TextAlign.center,
), ),
),
pw.SizedBox(height: 2), pw.SizedBox(height: 2),
], ],
),
); );
}, },
), ),

Loading…
Cancel
Save