a
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'package:flutter/foundation.dart'; // Per kIsWeb
|
||||||
|
import 'dart:io' show Platform;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||||
@@ -179,19 +181,25 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
|||||||
_ActionButton(
|
_ActionButton(
|
||||||
icon: Icons.print,
|
icon: Icons.print,
|
||||||
label: "Ricevuta A4",
|
label: "Ricevuta A4",
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
TicketPdfService().generateTicketReceipt(ticket);
|
final doc = await TicketPdfService()
|
||||||
|
|
||||||
// 1. Costruiamo la struttura (velocissimo)
|
|
||||||
/* final doc = await TicketPdfService()
|
|
||||||
.generateTicketReceipt(ticket);
|
.generateTicketReceipt(ticket);
|
||||||
|
final bytes = await doc.save();
|
||||||
|
final fileName = 'Ricevuta_${ticket.referenceId}.pdf';
|
||||||
|
|
||||||
// 2. Lanciamo layoutPdf esattamente come facevi tu!
|
if (kIsWeb || Platform.isMacOS) {
|
||||||
|
// Forza il download/salvataggio senza passare per il print spooler
|
||||||
|
await Printing.sharePdf(
|
||||||
|
bytes: bytes,
|
||||||
|
filename: fileName,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Su Android/iOS continuiamo a usare la stampa diretta che funziona
|
||||||
await Printing.layoutPdf(
|
await Printing.layoutPdf(
|
||||||
name: 'Ricevuta_${ticket.referenceId}.pdf',
|
onLayout: (format) async => bytes,
|
||||||
onLayout: (PdfPageFormat format) async =>
|
name: fileName,
|
||||||
doc.save(), // La magia è qui!
|
);
|
||||||
); */
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (company.labelFormat != LabelFormat.none)
|
if (company.labelFormat != LabelFormat.none)
|
||||||
@@ -201,12 +209,23 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
final doc = await TicketPdfService().generateLabelPdf(
|
final doc = await TicketPdfService().generateLabelPdf(
|
||||||
ticket,
|
ticket,
|
||||||
company,
|
|
||||||
);
|
);
|
||||||
|
final bytes = await doc.save();
|
||||||
|
final fileName = 'Ricevuta_${ticket.referenceId}.pdf';
|
||||||
|
|
||||||
|
if (kIsWeb || Platform.isMacOS) {
|
||||||
|
// Forza il download/salvataggio senza passare per il print spooler
|
||||||
|
await Printing.sharePdf(
|
||||||
|
bytes: bytes,
|
||||||
|
filename: fileName,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Su Android/iOS continuiamo a usare la stampa diretta che funziona
|
||||||
await Printing.layoutPdf(
|
await Printing.layoutPdf(
|
||||||
name: 'Etichetta_${ticket.referenceId}.pdf',
|
onLayout: (format) async => bytes,
|
||||||
onLayout: (PdfPageFormat format) async => doc.save(),
|
name: fileName,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_ActionButton(
|
_ActionButton(
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
import 'package:pdf/pdf.dart';
|
import 'package:pdf/pdf.dart';
|
||||||
@@ -10,7 +12,7 @@ class TicketPdfService {
|
|||||||
final CompanyModel company = GetIt.I.get<SessionCubit>().state.company!;
|
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<void> generateTicketReceipt(TicketModel ticket) async {
|
Future<pw.Document> generateTicketReceipt(TicketModel ticket) 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
|
||||||
@@ -64,9 +66,7 @@ class TicketPdfService {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final savedPdf = await pdf.save();
|
return pdf;
|
||||||
|
|
||||||
await Printing.layoutPdf(onLayout: (PdfPageFormat format) => savedPdf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper per costruire una singola metà (Cliente o Negozio)
|
/// Helper per costruire una singola metà (Cliente o Negozio)
|
||||||
@@ -282,10 +282,7 @@ class TicketPdfService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<pw.Document> generateLabelPdf(
|
Future<pw.Document> generateLabelPdf(TicketModel ticket) async {
|
||||||
TicketModel ticket,
|
|
||||||
CompanyModel company,
|
|
||||||
) async {
|
|
||||||
final pdf = pw.Document();
|
final pdf = pw.Document();
|
||||||
final font = await PdfGoogleFonts.robotoRegular();
|
final font = await PdfGoogleFonts.robotoRegular();
|
||||||
final boldFont = await PdfGoogleFonts.robotoBold();
|
final boldFont = await PdfGoogleFonts.robotoBold();
|
||||||
|
|||||||
Reference in New Issue
Block a user