print method

Future<void> print()

Implementation

Future<void> print() async {
  switch (state.printStatus) {
    case PrintStatus.preProcessing:
      pdfDoc = await generatePdf(PdfPageFormat.a4.landscape, state.test);

      if (state.action == PrintAction.print) {
        await Printing.layoutPdf(
            format: PdfPageFormat.a4.landscape,
            onLayout: (PdfPageFormat format) async => pdfDoc.save()
        );
        emit(state.copyWith(isLoadingPrint: false));
      } else {
        await Printing.sharePdf(bytes: await pdfDoc.save(), filename: 'Test.pdf');
        emit(state.copyWith(isLoadingShare: false));
      }
      break;
    case PrintStatus.generateFile:
      break;
    case PrintStatus.generatingPrint:
      pdfDoc.addPage(
        pdf.MultiPage(
          pageFormat: PdfPageFormat.a4,
          build: (pdf.Context context) => <pdf.Widget>[
            pdf.Text("hello"),
          ],
        ),
      );
      emit(state.copyWith(printStatus: PrintStatus.fileReady));
      break;
    case PrintStatus.fileReady:
      break;
  }
  emit(state.copyWith(printStatus: PrintStatus.preProcessing));
}