prova con metodo pdf vecchio programma assistenza
This commit is contained in:
@@ -179,17 +179,19 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
|||||||
_ActionButton(
|
_ActionButton(
|
||||||
icon: Icons.print,
|
icon: Icons.print,
|
||||||
label: "Ricevuta A4",
|
label: "Ricevuta A4",
|
||||||
onTap: () async {
|
onTap: () {
|
||||||
|
TicketPdfService().generateTicketReceipt(ticket);
|
||||||
|
|
||||||
// 1. Costruiamo la struttura (velocissimo)
|
// 1. Costruiamo la struttura (velocissimo)
|
||||||
final doc = await TicketPdfService()
|
/* final doc = await TicketPdfService()
|
||||||
.generateTicketReceipt(ticket, company);
|
.generateTicketReceipt(ticket);
|
||||||
|
|
||||||
// 2. Lanciamo layoutPdf esattamente come facevi tu!
|
// 2. Lanciamo layoutPdf esattamente come facevi tu!
|
||||||
await Printing.layoutPdf(
|
await Printing.layoutPdf(
|
||||||
name: 'Ricevuta_${ticket.referenceId}.pdf',
|
name: 'Ricevuta_${ticket.referenceId}.pdf',
|
||||||
onLayout: (PdfPageFormat format) async =>
|
onLayout: (PdfPageFormat format) async =>
|
||||||
doc.save(), // La magia è qui!
|
doc.save(), // La magia è qui!
|
||||||
);
|
); */
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (company.labelFormat != LabelFormat.none)
|
if (company.labelFormat != LabelFormat.none)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||||
|
import 'package:get_it/get_it.dart';
|
||||||
import 'package:pdf/pdf.dart';
|
import 'package:pdf/pdf.dart';
|
||||||
import 'package:pdf/widgets.dart' as pw;
|
import 'package:pdf/widgets.dart' as pw;
|
||||||
import 'package:printing/printing.dart';
|
import 'package:printing/printing.dart';
|
||||||
@@ -5,18 +7,15 @@ import 'package:flux/features/tickets/models/ticket_model.dart';
|
|||||||
import 'package:flux/features/company/models/company_model.dart';
|
import 'package:flux/features/company/models/company_model.dart';
|
||||||
|
|
||||||
class TicketPdfService {
|
class TicketPdfService {
|
||||||
|
final CompanyModel company = GetIt.I.get<SessionCubit>().state.company!;
|
||||||
|
|
||||||
/// Funzione principale: Genera il PDF A4 con le due metà
|
/// Funzione principale: Genera il PDF A4 con le due metà
|
||||||
Future<pw.Document> generateTicketReceipt(
|
Future<void> generateTicketReceipt(TicketModel ticket) async {
|
||||||
TicketModel ticket,
|
|
||||||
CompanyModel company,
|
|
||||||
) async {
|
|
||||||
final pdf = pw.Document();
|
final pdf = pw.Document();
|
||||||
|
|
||||||
// Carichiamo il font per essere sicuri che i caratteri siano ok
|
// Carichiamo il font per essere sicuri che i caratteri siano ok
|
||||||
final font = await PdfGoogleFonts.robotoRegular();
|
final font = await PdfGoogleFonts.robotoRegular();
|
||||||
final boldFont = await PdfGoogleFonts.robotoBold();
|
final boldFont = await PdfGoogleFonts.robotoBold();
|
||||||
/* final font = pw.Font.helvetica();
|
|
||||||
final boldFont = pw.Font.helveticaBold(); */
|
|
||||||
|
|
||||||
pdf.addPage(
|
pdf.addPage(
|
||||||
pw.Page(
|
pw.Page(
|
||||||
@@ -61,7 +60,9 @@ class TicketPdfService {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return pdf;
|
await Printing.layoutPdf(
|
||||||
|
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper per costruire una singola metà (Cliente o Negozio)
|
/// Helper per costruire una singola metà (Cliente o Negozio)
|
||||||
|
|||||||
Reference in New Issue
Block a user