63 lines
No EOL
2.7 KiB
Dart
63 lines
No EOL
2.7 KiB
Dart
import 'package:pdf/pdf.dart';
|
|
import 'package:pdf/widgets.dart' as pw;
|
|
import 'package:printing/printing.dart';
|
|
import '../splitter/splitter_provider.dart';
|
|
import '../calculator/calculator_provider.dart';
|
|
|
|
class PdfService {
|
|
static Future<void> generateSplitterReport(
|
|
double userTotal,
|
|
List<FriendExpense> friends,
|
|
List<String> settlements,
|
|
List<HistoryItem> userHistory
|
|
) async {
|
|
final pdf = pw.Document();
|
|
|
|
// Font Google per risolvere il problema dei segni strani
|
|
final font = await PdfGoogleFonts.robotoRegular();
|
|
final fontBold = await PdfGoogleFonts.robotoBold();
|
|
|
|
pdf.addPage(pw.Page(
|
|
build: (pw.Context context) => pw.Column(
|
|
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
|
children: [
|
|
pw.Text("Report - Spese Dettagliate", style: pw.TextStyle(font: fontBold, fontSize: 20)),
|
|
pw.SizedBox(height: 20),
|
|
|
|
// Tabella Io (Tua cronologia esplosa)
|
|
pw.Text("I TUOI ANTICIPI:", style: pw.TextStyle(font: fontBold, fontSize: 12)),
|
|
pw.Table(
|
|
border: pw.TableBorder.all(color: PdfColors.grey400, width: 0.5),
|
|
children: [
|
|
...userHistory.map((item) => pw.TableRow(children: [
|
|
pw.Padding(padding: const pw.EdgeInsets.all(5), child: pw.Text(item.note.isEmpty ? "Spesa" : item.note, style: pw.TextStyle(font: font))),
|
|
pw.Padding(padding: const pw.EdgeInsets.all(5), child: pw.Text("${item.result} €", style: pw.TextStyle(font: font))),
|
|
])),
|
|
],
|
|
),
|
|
|
|
pw.SizedBox(height: 20),
|
|
|
|
// Tabella Amici (Inclusa nota)
|
|
pw.Text("ANTICIPI ALTRI PARTECIPANTI:", style: pw.TextStyle(font: fontBold, fontSize: 12)),
|
|
pw.Table(
|
|
border: pw.TableBorder.all(color: PdfColors.grey400, width: 0.5),
|
|
children: [
|
|
...friends.map((f) => pw.TableRow(children: [
|
|
pw.Padding(padding: const pw.EdgeInsets.all(5), child: pw.Text(f.name, style: pw.TextStyle(font: font))),
|
|
pw.Padding(padding: const pw.EdgeInsets.all(5), child: pw.Text(f.note.isEmpty ? "-" : f.note, style: pw.TextStyle(font: font))),
|
|
pw.Padding(padding: const pw.EdgeInsets.all(5), child: pw.Text("${f.spent.toStringAsFixed(2)} €", style: pw.TextStyle(font: font))),
|
|
])),
|
|
],
|
|
),
|
|
|
|
pw.SizedBox(height: 30),
|
|
pw.Text("BILANCIO FINALE:", style: pw.TextStyle(font: fontBold, fontSize: 12)),
|
|
pw.Divider(thickness: 0.5),
|
|
...settlements.map((s) => pw.Text(s, style: pw.TextStyle(font: font))),
|
|
],
|
|
),
|
|
));
|
|
await Printing.layoutPdf(onLayout: (format) async => pdf.save());
|
|
}
|
|
} |