如何在Flatter中从应用程序目录加载pdf文件?

如何在Flatter中从应用程序目录加载pdf文件?,pdf,flutter,flutter-dependencies,Pdf,Flutter,Flutter Dependencies,我正在尝试从应用程序目录加载PDF文件,我尝试从url加载它,它工作正常,不需要从应用程序目录加载已经下载的PDF 这是我用来查看PDFflatter\u pdfview的软件包,在尝试从url加载它时效果很好,现在我需要的是从目录加载一个已经下载的PDF 为了从目录加载文件,我尝试了以下方法: var dir = await getApplicationDocumentsDirectory(); File file = File('${dir.path}/$pName.pdf'); boo

我正在尝试从应用程序目录加载PDF文件,我尝试从url加载它,它工作正常,不需要从应用程序目录加载已经下载的PDF

这是我用来查看PDF
flatter\u pdfview
的软件包,在尝试从url加载它时效果很好,现在我需要的是从目录加载一个已经下载的PDF

为了从目录加载文件,我尝试了以下方法:


var dir = await getApplicationDocumentsDirectory();
File file = File('${dir.path}/$pName.pdf');

bool  fileExists = File(await '${dir.path}/$pName.pdf')
                  .existsSync();

             if(fileExists)
                {
                  urlPdfPath = file.toString();
                  print('url pdf path $urlPdfPath');
                  Navigator.push(context, MaterialPageRoute(builder: (context) {
                    return PdfViewer(
                      path: urlPdfPath,
                      product: pName,
                    );
                  }));

                }


当我运行这个时,我得到了一个异常

D/AndroidRuntime( 4565): Shutting down VM
E/AndroidRuntime( 4565): FATAL EXCEPTION: main
E/AndroidRuntime( 4565): java.lang.IllegalArgumentException: Unsupported value: java.io.FileNotFoundException: No such file or directory

在代码中:


更改-
urlPdfPath=file.toString()
to
urlPdfPath=file.path

您在这方面面临的具体问题是什么获取目录路径-
var\u dir=wait getApplicationDocumentsDirectory()
然后获取文件-
file\u file=file(“${u dir.path}/$fileName.pdf”)
然后将
\u文件
传递给您正在使用的PDFviewer。我已经这样做了,但这会引发无法打开的异常。粘贴您正在使用的代码和PDF包&您也没有提到有问题的错误。没有这些,谁能帮上忙。?@anmol.majhail我已经更新了我的问题,请看一看不是-
urlPdfPath=file.toString()
应该是
urlPdfPath=file.path