showPrintPreview static method

Future<void> showPrintPreview({
  1. required ReportTemplate template,
  2. required List data,
  3. PdfExportOptions options = const PdfExportOptions(),
})

Shows the print preview

Implementation

static Future<void> showPrintPreview({
  required ReportTemplate template,
  required List<dynamic> data,
  PdfExportOptions options = const PdfExportOptions(),
}) async {
  await Printing.layoutPdf(
    onLayout: (PdfPageFormat format) async {
      final pdf = pw.Document();
      final pageFormat = _getPageFormat(template);

      for (int i = 0; i < data.length; i++) {
        final item = data[i];

        if (template.reportType == ReportType.label) {
          await _addLabelsPage(pdf, template, item, pageFormat, options);
        } else {
          await _addDocumentPage(pdf, template, item, pageFormat, options);
        }
      }

      return await pdf.save();
    },
    name: '${template.name}_${DateTime.now().millisecondsSinceEpoch}',
  );
}