[英]How to open PDF file from internal storage in flutter
用於代碼的插件
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
...
請嘗試其中任何一個
pdf:^3.3.0,flutter_full_pdf_viewer:^1.0.6,syncfusion_flutter_pdfviewer:^19.1.58-beta,syncfusion_flutter_pdfviewer_platform_interface:^19.1.58-beta
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.