4 changed files with 144 additions and 33 deletions
@ -0,0 +1,77 @@ |
|||
import 'package:pdf/widgets.dart' as pw; |
|||
import 'package:pdf/pdf.dart'; |
|||
import 'package:printing/printing.dart'; |
|||
import '../pages/commandes_screen.dart'; |
|||
Future<void> printOrderPDF(Order order) async { |
|||
|
|||
String _formatTime(DateTime dateTime) { |
|||
return '${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')} ${dateTime.day.toString().padLeft(2, '0')}/${dateTime.month.toString().padLeft(2, '0')}/${dateTime.year}'; |
|||
} |
|||
final pdf = pw.Document(); |
|||
|
|||
final pageFormat = PdfPageFormat( |
|||
204.1, // 72 mm imprimable |
|||
595.0, // 210 mm |
|||
marginAll: 0, |
|||
); |
|||
|
|||
pdf.addPage( |
|||
pw.Page( |
|||
pageFormat: pageFormat, |
|||
build: (pw.Context context) { |
|||
return pw.Padding( |
|||
padding: const pw.EdgeInsets.fromLTRB(6, 6, 6, 18), |
|||
child: pw.Column( |
|||
crossAxisAlignment: pw.CrossAxisAlignment.start, |
|||
children: [ |
|||
pw.Divider(), |
|||
pw.Text('Commande n° ${order.numeroCommande}', style: pw.TextStyle(fontSize: 10, fontWeight: pw.FontWeight.bold)), |
|||
pw.Text('Table: ${order.tablename}', style: pw.TextStyle(fontSize: 8)), |
|||
pw.Text('Date: ${_formatTime(order.dateCommande)}', style: pw.TextStyle(fontSize: 8)), |
|||
pw.SizedBox(height: 8), |
|||
pw.Divider(), |
|||
pw.SizedBox(height: 8), |
|||
pw.Row( |
|||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, |
|||
children: [ |
|||
pw.Text('Désignation', style: pw.TextStyle(fontSize: 9, fontWeight: pw.FontWeight.bold)), |
|||
pw.Text('Cocher', style: pw.TextStyle(fontSize: 9)), |
|||
], |
|||
), |
|||
pw.SizedBox(height: 8), |
|||
pw.Divider(), |
|||
...order.items.map( |
|||
(item) => pw.Row( |
|||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, |
|||
children: [ |
|||
pw.Container( |
|||
width: 120, |
|||
child: pw.Text( |
|||
'${item.quantite} x ${item.nom ?? 'Item'}', |
|||
style: pw.TextStyle(fontSize: 8), |
|||
), |
|||
), |
|||
pw.Container( |
|||
width: 10, |
|||
height: 10, |
|||
decoration: pw.BoxDecoration( |
|||
border: pw.Border.all(width: 1), |
|||
), |
|||
), |
|||
], |
|||
), |
|||
), |
|||
pw.Divider(), |
|||
pw.Spacer(), |
|||
pw.SizedBox(height: 10), // marge visible en bas |
|||
], |
|||
), |
|||
); |
|||
}, |
|||
), |
|||
); |
|||
|
|||
await Printing.layoutPdf( |
|||
onLayout: (PdfPageFormat format) async => pdf.save(), |
|||
); |
|||
} |
|||
Loading…
Reference in new issue