![](/img/trans.png)
[英]How to use the MuPDF library to open pdf files when a pdf file is opened from webview
[英]How to use this library to show a PDF when this screen is opened in Flutter
我有一個pdf_screen.dart文件,它會在打開時直接顯示PDF,是否有人可以解釋我如何使用這個名為flutter pdf viewer的庫的功能來顯示我的pdf?
class _PdfScreenState extends State<PdfScreen> {
final DocumentSnapshot document;
String path;
var dir;
_PdfScreenState(this.document);
@override
void initState() {
super.initState();
getPdf();
}
Future<void> getPdf() async {
try {
dir = await getApplicationDocumentsDirectory();
setState(() {
path = "${dir.path}/${document["title"]}.pdf";
});
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
if (path == null) {
print("loading");
return Container(
color: Colors.white,
child: Center(
child: CircularProgressIndicator(backgroundColor: Colors.blueAccent,
),
),
);
} else {
return Container(
child: ??; // I need to show my PDF here, I need to pass the path
// variable but PdfViewer is a function and it doesn't
// return a widget, how to implement?
}
}
}
正如自述文件所述,此庫啟動了一個新的意圖,因此它會替換堆棧中的Flutter應用程序,直到您使用后退按鈕。 這個例子很清楚如何實現這一目標。
但是,隨着自述文件的繼續,可以使用概念驗證,允許您在Flutter應用程序中呈現PDF。 查看github的分支以了解更多信息。
內聯分支機構提供內聯PDF的概念驗證。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.