繁体   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