'Download file to Device download folder in Flutter

I'm trying to download files in my flutter app using the dio plugin for which I have to specify a "savePath". But using path_provider I can only see ApplicationDocumentsDirectory, ExternalStorageDirectory etc. My idea is to simply show the file(pdf) in the device's Download Folder, so whenever the user wants to view the file, he just goes to the folder and clicks it. Saving to ApplicationDocumentsDirectory (as I understood it) would require me to provide a link (of sorts) to the file in the app, meaning the user would have to open my app every time he wants to view files downloaded through my app.

I just want the files to be available in the DownLoads Folder, just like with so many files we download directly to the DownLoads Folder.

Am I missing something here? pls enlighten me!

Added this code on request from user in comments:

var dir;
Future < dynamic > downloadFile(url, filename) async {
  Dio dio = Dio();

  try {
    //  checkPermission();
    //if(Externa)
    dir = await getApplicationDocumentsDirectory();
    if (dir.path != null)
      print("url:$url");
    print("path:${dir.path}/$filename");
    if (await File("${dir.path}/$filename").exists()) {
      setState(() {

        filePath = "${dir.path}/$filename";
      });
      return;
    }
    await dio.download(url, "${dir.path}/$filename",
      onReceiveProgress: (rec, total) {
        print("Rec: $rec , Total: $total");

        setState(() {
          downloading = true;
          progressString = ((rec / total) * 100).toStringAsFixed(0) + "%";
        });
      });
  } catch (e) {
    print("downloadErr:$e");
  }

  setState(() {
    downloading = false;
    progressString = "Concluido";
    filePath = "${dir.path}/$filename";

  });

}


Solution 1:[1]

You can use downloads_path_provider for it

https://pub.dev/packages/downloads_path_provider

import 'package:downloads_path_provider/downloads_path_provider.dart';  

Future<Directory> downloadsDirectory = DownloadsPathProvider.downloadsDirectory;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1