samedi 13 mars 2021

Flutter web on mobile/safari download file

I have my app generating a PDF file, I didn't find any solution to have the file downloaded when my flutter PWA is running in safari for iOS or Chrome. Is working perfectly fine in desktop web browser. thank you!!!

This below is the portion that open the file but causing the crash of the app, I know that is not ideal, but I cannot find another solution, if any.

generateDailyTimeSheet(PdfPageFormat.letter, globals.timeCardDate).then((pdf) =>
            Printing.sharePdf(bytes: pdf, filename: 'myfile.pdf'));

here my function:

void PDFDownload(List<DailyTimeSheetStrip> dailyTimeSheetLocalListX) async {
 
  File file;
 
  if (!kIsWeb) {
  //if is not web it send an email with the file attached
    await getTemporaryDirectory()
        .then((output) => file = File("${output.path}/" +
            (globals.projectInUse.dailyShort ?? 'DTS') +
            "_${_fileName(globals.timeCardDate)}_${globals.project}.pdf"))
        .whenComplete(() {
      generateDailyTimeSheet(PdfPageFormat.letter, globals.timeCardDate).then((value) async {
        await file.writeAsBytes(value).whenComplete(() {
          FlutterEmailSender.send(Email(
            body: 'Created by my App',
            subject: 'myfileto send',
            cc: dailyTimeSheetLocalListX.map((d) => d.email).toList(),
            recipients: ['myemail@email.com],
            attachmentPaths: [file.path],
            isHTML: false,
          ));
        });
      });
    });
  } else {

   // here where the problem is! 
    generateDailyTimeSheet(PdfPageFormat.letter, globals.timeCardDate).then((pdf) =>
        Printing.sharePdf(bytes: pdf, filename: 'myfile.pdf'));
  }
}



Aucun commentaire:

Enregistrer un commentaire