Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to download pdf to mobile device flutter

Hello I have this method that gets pdf from api and returns decoded file, I am able to display it on click, but i want to save it to device.
Here is my method for decoding pdf:

  Future<File> _storeFile(String bytes) async {
    final filename = "${_dokument?.naziv}";
    final bytes = _dokument?.bytes;
    Uint8List base64Decode(String source) => base64.decode(source);

    await checkDocumentFolder();

    String dir = directory!.path;

    //final file = File('${dir.path}/$filename');
    final file = File('$dir/$filename');
    //var pdfBytes = bytes?.split(",")[1];
    if (!file.existsSync()) file.create();
    var pdfBytes = bytes?.substring(bytes.indexOf(",") + 1);
    print(pdfBytes);
    await file.writeAsBytes(base64Decode(pdfBytes!), flush: true);

    return file;
  }

So my question is, can i somehow save file returned from this method to mobile device.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

yes you can store your file in device
i suggest you to see this article and this

also you can use file_saver package to store file all platform flutter support

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading