flutterdartpdfopenpdf

how can open pdf file in flutter


I need to add code to open a pdf file in the flutter project, this is my code:

grid.draw(
    page: document.pages.add(),

    bounds: const Rect.fromLTWH(0, 0, 0, 0));

    final fileName = 'Output${DateTime.now()}.pdf';

    print('dir $dir');
    try {
    final file = File("${dir}/$fileName");
      
    print('file $file');
      

    await file.writeAsBytes(await document.save(), flush: true);
    print('saved');
    } catch (e) {
    print('error ${e}');
    }
    

    document.dispose();
  }
  
} catch (e) {
  print(e);
}

Solution

  • you can use the open_filex package to open a pdf file by calling the device apps, and give it a try.

    another package that might help is pdfx package.