【发布时间】:2021-07-07 00:33:25
【问题描述】:
代码使用插件
native_pdf_view: ^4.0.1
出现错误的示例代码,我可以使用资产中的 pdf 文件,但无法从本地存储中加载 pdf
return Container(
child: PdfView(
controller:
// sample,
PdfController(
document: PdfDocument.openFile(widget.path),
),
onDocumentLoaded: (document) {
setState(() {
isLoaded = true;
});
},
pageLoader: Center(child: CircularProgressIndicator()),
),
);
错误,表示文件未找到,但此文件路径是从现有文件中提取的
D/PDF_RENDER( 585): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf
D/PDF_RENDER( 585): OpenAssetDocument. Created file: /data/user/0/com.example.doc_holder/cache/992d7c88890d40268ae7ac4103bf96ba.pdf
D/PDF_RENDER( 585): OpenFileDocument. File: /data/user/0/com.example.doc_holder/cache/992d7c88890d40268ae7ac4103bf96ba.pdf
D/PDF_RENDER( 585): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf
════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building PdfView(dirty, state: _PdfViewState#6990d):
Null check operator used on a null value
The relevant error-causing widget was
PdfView
lib/const/pdf.dart:23
When the exception was thrown, this was the stack
#0 _PdfViewState._buildLoaded
package:native_pdf_view/src/native_pdf_view.dart:172
#1 _PdfViewState.build
package:native_pdf_view/src/native_pdf_view.dart:205
#2 StatefulElement.build
package:flutter/…/widgets/framework.dart:4683
#3 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4566
#4 StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4738
...
【问题讨论】:
-
有时当你对资产做了错误的事情并在之后修复它时,直到你在模拟器上删除并重新安装应用程序后它才会起作用,所以试试吧
-
我试过了,但它仍然给出同样的错误。错误导致第二行 pdfView() 中的小部件当我尝试从项目的资产文件夹中打开 pdf 时,它的工作正常