Flutter 如果我将文件放在getApplicationDocumentsDirectory()目录中,文件将存储在哪里?它会增加应用程序的大小吗? Future downloadFile()异步{ Dio Dio=Dio(); 试一试{ var dir=等待getApplicationDocumentsDirectory(); 打印('DIR是:${DIR}'); 等待dio.download(pdfUrl,${dir.path}/sample.pdf),onReceiveProgress:(rec,total){ 打印('rec:${rec},total:${total}'); 设置状态(){ 下载=真; progressString=(记录/总计)*100.ToStringsFixed(0)+“%”; }); }); }捕获(e){ 印刷品(e); } 设置状态(){ 下载=假; progressString=“已完成”; }); 打印(“下载完成”); }

Flutter 如果我将文件放在getApplicationDocumentsDirectory()目录中,文件将存储在哪里?它会增加应用程序的大小吗? Future downloadFile()异步{ Dio Dio=Dio(); 试一试{ var dir=等待getApplicationDocumentsDirectory(); 打印('DIR是:${DIR}'); 等待dio.download(pdfUrl,${dir.path}/sample.pdf),onReceiveProgress:(rec,total){ 打印('rec:${rec},total:${total}'); 设置状态(){ 下载=真; progressString=(记录/总计)*100.ToStringsFixed(0)+“%”; }); }); }捕获(e){ 印刷品(e); } 设置状态(){ 下载=假; progressString=“已完成”; }); 打印(“下载完成”); },flutter,flutter-dependencies,Flutter,Flutter Dependencies,我想存储下载的pdf供脱机使用,如何实现它?如何在下载/(sample.pdf)本地文件夹中保存文件,并在脱机时检索文件?在iOS上,这使用了NSDocumentDirectory API。如果数据不是用户生成的,请考虑使用GETApple Studio目录, 在Android上,它在上下文上使用getDataDirectory API。如果数据对用户是可见的,请考虑使用GETEXPLAL存储目录。< /P> 所以我不知道应用程序大小意味着什么?如果你下载一个文件到应用程序的目录,这将明显增加应

我想存储下载的pdf供脱机使用,如何实现它?如何在下载/(sample.pdf)本地文件夹中保存文件,并在脱机时检索文件?

在iOS上,这使用了NSDocumentDirectory API。如果数据不是用户生成的,请考虑使用GETApple Studio目录,

在Android上,它在上下文上使用getDataDirectory API。如果数据对用户是可见的,请考虑使用GETEXPLAL存储目录。< /P>
所以我不知道应用程序大小意味着什么?如果你下载一个文件到应用程序的目录,这将明显增加应用程序缓存或其他大小,但不会增加apk大小。

我说的应用程序大小是指apk大小。所以你根本不会增加apk大小。
Future<void> downloadFile() async{
    Dio dio = Dio() ;
    try{
      var dir = await getApplicationDocumentsDirectory();
      print('DIR is :${dir}');
      await dio.download(pdfUrl, "${dir.path}/sample.pdf",onReceiveProgress: (rec,total){
        print('rec:${rec},total:${total}');

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

    setState(() {
      downloading = false;
      progressString = "Completed";
    });
    print("Download completed");
  }