Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to update PDFView filePath or pdfData? #216

Closed
shinxxxxwon opened this issue Dec 14, 2022 · 4 comments
Closed

how to update PDFView filePath or pdfData? #216

shinxxxxwon opened this issue Dec 14, 2022 · 4 comments

Comments

@shinxxxxwon
Copy link

In PDFView Widget, the pdf is displayed on the screen as the pdfData variable. The first pdf is displayed well, but later the pdf may be changed. Is there a way to update the UI with the changed pdf when the pdf changes?

@shinxxxxwon
Copy link
Author

The update using the key value was successful.

@shinxxxxwon
Copy link
Author

shinxxxxwon commented Dec 23, 2022

In debug mode, it is updated normally, but in release mode, pdf is not changed as a key value.

Consumer<PDFProvider>(
            builder: (context, pdf, child){
              return PDFView(
                key: ValueKey(pdf.keyCount),
                pdfData: pdf.uinPdfData!,
                enableSwipe: true,
                swipeHorizontal: true,
                autoSpacing: false,
                pageFling: false,
                defaultPage: 0,
                onRender: (_pages) {
                  setState(() {
                    isReady = true;
                  });
                },
                onError: (error) {
                  print(error.toString());
                },
                onPageError: (page, error) {
                  print('$page: ${error.toString()}');
                },
                // onViewCreated: (PDFViewController pdfViewController) {
                //   _controller.complete(pdfViewController);
                // },
                onPageChanged: (int? page, int? total) {
                  setState(() {
                    nPageIndex = page! + 1;
                  });
                },
              );
            },
          ),

@shinxxxxwon
Copy link
Author

If you change the page after changing pdfData in release mode, pdf will be updated. Is there a way to update the PdfView widget when pdfData changes?

@loginleng
Copy link

Simple use of 'Visiblity';
ValueNotifier<String?> pdfUrl = ValueNotifier(null);
initState(){ super.initState(); pdfUrl.value = widget.data[0]['url']; pdfUrl.addListener(() { setState(() { showPdf = false; }); WidgetsBinding.instance!.addPostFrameCallback((_) { setState(() { showPdf = true; }); }); }); }
Visibility( visible: showPdf, child: PDF( swipeHorizontal: true, ).cachedFromUrl( pdfUrl.value!, ), )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants