im working on a project that require in a certain moment to generate and print a document. I've done this using pdf and printing packages. It all works fine if im in the debug mode, but not in the builded version.
I also added the script recommended for the web:
<script>
var dartPdfJsVersion = "3.2.146";
</script>
This is the code i used:
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
import 'package:sostituzione_docenti/providers/gestione_docenti_provider.dart';
import '../classes/control.dart';
class PdfService {
static Future<void> printOrario(
List<List>? orario, DatoDocente docente) async {
final doc = pw.Document();
List<String> header = ["Ora/Giorno", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"];
doc.addPage(pw.Page(
pageFormat: PdfPageFormat.a4,
orientation: pw.PageOrientation.landscape,
margin: const pw.EdgeInsets.only(top: 50, right: 100, left: 50, bottom: 100),
build: (pw.Context context) {
return pw.Column(
children: [
pw.Text("Orario di ${docente.cognome} ${docente.nome}"),
pw.SizedBox(height: 10),
pw.Row(
children: [
for (int a = 0; a < header.length; a++) ...{
pw.Expanded(
child: pw.SizedBox(
height: 50,
child: pw.Container(
decoration: pw.BoxDecoration(
border: pw.Border.all(color: PdfColors.black),
color: PdfColors.green100),
child: pw.Center(child: pw.Text(header[a]))),
)),
}
],
),
for (int i = 0; i < Control.maxH; i++) ...{
pw.Row(
children: [
pw.Expanded(
child: pw.SizedBox(
height: 70,
child: pw.Container(
decoration: pw.BoxDecoration(
border: pw.Border.all(color: PdfColors.black),
color: PdfColors.green100),
child: pw.Center(child: pw.Text("${i + 1} ora"))),
)),
for (int j = 0; j < 6; j++) ...{
pw.Expanded(
child: pw.SizedBox(
height: 70,
child: pw.Container(
decoration: pw.BoxDecoration(
border: pw.Border.all(color: PdfColors.black),
color: orario![i][j] != null
? PdfColors.amber100
: PdfColors.white),
child: pw.Center(
child: orario[i][j] == null
? pw.Text(" ")
: pw.Text(orario[i][j]))),
)),
}
],
)
}
],
);
}));
await Printing.layoutPdf(onLayout: (PdfPageFormat format) async => doc.save());
}
}
Does anyone can help me?
Edit: those are the errors i get in the browser:
Uncaught Unsupported operation: Platform._operatingSystem