簡體   English   中英

如何在Flutter中打開此屏幕時使用此庫顯示PDF

[英]How to use this library to show a PDF when this screen is opened in Flutter

我有一個pdf_screen.dart文件,它會在打開時直接顯示PDF,是否有人可以解釋我如何使用這個名為flutter pdf viewer的庫的功能來顯示我的pdf?

Flutter PDF Viewer Library示例

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM