简体   繁体   English

如何在Flutter中打开此屏幕时使用此库显示PDF

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

I have a pdf_screen.dart file that will show a PDF directly when opened, does anyone can explain me how to use the functions of this library called flutter pdf viewer just to show my pdf? 我有一个pdf_screen.dart文件,它会在打开时直接显示PDF,是否有人可以解释我如何使用这个名为flutter pdf viewer的库的功能来显示我的pdf?

Flutter PDF Viewer Library Example 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?
    }
  }
}

As the readme says, this library launches a new intent, so it replaces your Flutter app in the stack until you use the back button. 正如自述文件所述,此库启动了一个新的意图,因此它会替换堆栈中的Flutter应用程序,直到您使用后退按钮。 The example is clear how to achieve this. 这个例子很清楚如何实现这一目标。

However, as the readme continues, a proof-of-concept is available allowing you to render the PDF inside your Flutter app. 但是,随着自述文件的继续,可以使用概念验证,允许您在Flutter应用程序中呈现PDF。 Check out the branch from github to explore more. 查看github的分支以了解更多信息。

A proof of concept for inline PDFs is available at the inline branch. 分支机构提供内联PDF的概念验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从WebView打开pdf文件时如何使用MuPDF库打开pdf文件 - How to use the MuPDF library to open pdf files when a pdf file is opened from webview Flutter 应用程序总是在屏幕锁定时打开 - Flutter apps always opened when screen locked 当通知到达时,如何在任何屏幕中显示自定义对话框? - How to show a custom dialog in any screen in when notification arrived flutter? 如何最小化所有打开的应用程序并显示主屏幕? - How to minimize all opened applications and show home screen? 当活动已打开时,如何在活动中打开屏幕? - How to turn on screen in an Activity when the Activity was already opened? 从后台打开应用程序时如何进入登录屏幕? - How to go to Login Screen when app is opened from background? Flutter,如何在键盘打开时无缝滚动视图 - Flutter, How to seamlessly scroll the view when keyboard opened 当屏幕打开时,带有 RecyclerView 的屏幕滚动到底部 - Screen with RecyclerView scrolled to bottom when screen is opened 使用 DialogFragment 和导航库时将对话框显示为全屏或对话框 - Show dialog as full screen or as dialog when using DialogFragment and Navigation Library 使用&#39;com.github.barteksc:android-pdf-viewer:2.8.2&#39;库打开pdf时出现黑屏 - Blank screen when opening a pdf using 'com.github.barteksc:android-pdf-viewer:2.8.2' library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM