import 'package:flutter/material.dart'; import 'package:pdf/pdf.dart'; import 'package:printing/printing.dart'; class PdfGenerator { static Future generatePdf(Invoice invoice, List items) async { final pdf = pw.Document(); pdf.addPage( pw.Page( build: (pw.Context context) => pw.Column( children: [ pw.Text('請求書'), pw.SizedBox(height: 20), pw.Text('顧客名: ${invoice.customerId}'), // 後で顧客名に変更 pw.Text('日付: ${invoice.date}'), pw.SizedBox(height: 20), pw.Table( border: pw.TableBorder.all(), children: [ pw.TableRow(children: [ pw.Text('商品名'), pw.Text('数量'), pw.Text('単価'), pw.Text('値引き'), pw.Text('小計'), ]), for (var item in items) pw.TableRow(children: [ pw.Text(item.productId.toString()), // 後で商品名に変更 pw.Text(item.quantity.toString()), pw.Text(item.unitPrice.toStringAsFixed(2)), pw.Text((item.discount * 100).toStringAsFixed(2) + '%'), pw.Text((item.unitPrice * item.quantity - (item.unitPrice * item.quantity * item.discount)).toStringAsFixed(2)), ]), ], ), pw.SizedBox(height: 20), pw.Row( mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, children: [ pw.Text('合計'), pw.Text(invoice.total.toStringAsFixed(2)), ], ), pw.Row( mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, children: [ pw.Text('税額'), pw.Text(invoice.tax.toStringAsFixed(2)), ], ), pw.Row( mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, children: [ pw.Text('値引き合計'), pw.Text(invoice.discountTotal.toStringAsFixed(2)), ], ), ], ), ), ); await Printing.sharePdf(bytes: pdf.save(), filename: 'invoice.pdf'); } }