-2

I'm working on my personal website over at dlblack.dev (all the text is placeholder for now, I'm learning Flutter through a tutorial then I'm going to go back and make it my own). Eventually, I want there to be an option in the navigation bar called "Resume" such that when you click it, it downloads a pdf of my resume to the user's device, from the location project/assets/resume.pdf.

My web development experience is pretty limited, this is my first time really throwing together a full site, but I like how Flutter/Dart feels like a lot of backend-focused languages I've learned, especially Java (essentially what that means is if you tell me to "just integrate how it's done from HTML/JS" or something like that, I'm gonna need more explanation).

Thanks.

VitaminTussle
  • 441
  • 1
  • 3
  • 12
  • I think you could try something like this: https://stackoverflow.com/a/60614367/3690032 – Max Weber May 12 '20 at 18:51
  • @MyracleDesign I saw that when I searched on Google, but from what I can tell that's for downloading a file from an external link to be used within the Flutter app. I could be wrong, but for example, I'd have no idea what to pass in as the "url" there, since the file is locally contained at a file location, not exactly an internet location. – VitaminTussle May 12 '20 at 18:54
  • 1
    Well, maybe I did not understand the question right, but you have a server that serves the file, and your Client (Your website) wants to download it. That should be possible. If the file is located on the device where the browser runs, then I believe it will not be possible because the Browser is strictly disallowed to access the file system. – Max Weber May 12 '20 at 18:58
  • Ah, ok. I'll go try it out, see if I can get it to work, and I'll keep you posted. – VitaminTussle May 12 '20 at 19:04
  • It did end up working! It downloads with a slightly changed filename, but that's fine, I think it's because i had it download from the assets folder instead of the same folder as the download service file I made. I'll fool around with it and see what I can do to fix the filename, but it's not a huge deal. Thanks so much! – VitaminTussle May 12 '20 at 19:12

1 Answers1

0

You can do something like this..

import 'dart:html' as html;

And..when you want to download something..

 onPressed: (){
                      html.window.open("<link of the file>", "text");
                    },

This is mostly suitable when you are having the file remotely.. even for the asset file it is Ok..!

srikanth7785
  • 1,382
  • 1
  • 7
  • 22