packages.flutter icon indicating copy to clipboard operation
packages.flutter copied to clipboard

[native_pdf_view] Open a certain page when document is loaded

Open MahmoudAshours opened this issue 5 years ago • 7 comments

Describe the bug I want to animate or jump to a certain page when document is loaded at the very start of rendering.

To Reproduce 1 - I tried to jump to a certain page when document is loaded in onDocumentLoaded: (PdfDocument document) { _pdfController.jumpToPage(10); },

But I faced an exception : Reloaded 9 of 868 libraries in 854ms. D/PDF_RENDER( 6672): OpenFileDocument. File: /data/user/0/projectname/cache/file_picker/Short-stories-from-100-Selected-Stories.pdf E/flutter ( 6672): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type '_AssertionError' is not a subtype of type 'Exception' [38;5;248mE/flutter ( 6672): #0 PdfController._loadDocument[39;49m E/flutter ( 6672): <asynchronous suspension> [38;5;248mE/flutter ( 6672): #1 PdfController._attach[39;49m [38;5;248mE/flutter ( 6672): #2 _PdfViewState.initState[39;49m [38;5;244mE/flutter ( 6672): #3 StatefulElement._firstBuild[39;49m [38;5;244mE/flutter ( 6672): #4 ComponentElement.mount[39;49m [38;5;244mE/flutter ( 6672): #5 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #6 Element.updateChild[39;49m [38;5;244mE/flutter ( 6672): #7 SingleChildRenderObjectElement.mount[39;49m [38;5;244mE/flutter ( 6672): #8 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #9 Element.updateChild[39;49m [38;5;244mE/flutter ( 6672): #10 ComponentElement.performRebuild[39;49m [38;5;244mE/flutter ( 6672): #11 Element.rebuild[39;49m [38;5;244mE/flutter ( 6672): #12 ComponentElement._firstBuild[39;49m [38;5;244mE/flutter ( 6672): #13 ComponentElement.mount[39;49m [38;5;244mE/flutter ( 6672): #14 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #15 Element.updateChild[39;49m [38;5;244mE/flutter ( 6672): #16 ComponentElement.performRebuild[39;49m [38;5;244mE/flutter ( 6672): #17 Element.rebuild[39;49m [38;5;244mE/flutter ( 6672): #18 ComponentElement._firstBuild[39;49m [38;5;244mE/flutter ( 6672): #19 ComponentElement.mount[39;49m [38;5;244mE/flutter ( 6672): #20 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #21 Element.updateChild[39;49m [38;5;244mE/flutter ( 6672): #22 ComponentElement.performRebuild[39;49m [38;5;244mE/flutter ( 6672): #23 Element.rebuild[39;49m [38;5;244mE/flutter ( 6672): #24 ComponentElement._firstBuild[39;49m [38;5;244mE/flutter ( 6672): #25 ComponentElement.mount[39;49m [38;5;244mE/flutter ( 6672): #26 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #27 Element.updateChild[39;49m [38;5;244mE/flutter ( 6672): #28 ComponentElement.performRebuild[39;49m [38;5;244mE/flutter ( 6672): #29 Element.rebuild[39;49m [38;5;244mE/flutter ( 6672): #30 ComponentElement._firstBuild[39;49m [38;5;244mE/flutter ( 6672): #31 ComponentElement.mount[39;49m [38;5;244mE/flutter ( 6672): #32 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #33 MultiChildRenderObjectElement.mount[39;49m [38;5;244mE/flutter ( 6672): #34 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #35 Element.updateChild[39;49m [38;5;244mE/flutter ( 6672): #36 ComponentElement.performRebuild[39;49m [38;5;244mE/flutter ( 6672): #37 StatefulElement.performRebuild[39;49m [38;5;244mE/flutter ( 6672): #38 Element.rebuild[39;49m [38;5;244mE/flutter ( 6672): #39 ComponentElement._firstBuild[39;49m [38;5;244mE/flutter ( 6672): #40 StatefulElement._firstBuild[39;49m [38;5;244mE/flutter ( 6672): #41 ComponentElement.mount[39;49m [38;5;244mE/flutter ( 6672): #42 Element.inflateWidget[39;49m [38;5;244mE/flutter ( 6672): #43 Element.updateChild[39;49m [38;5;244mE/flutter ( 6672): #44 ComponentElement.performRebuild[39;49m E/flutter ( 6672): #45 Element.rebuild (package:flutter/src/w

Expected behavior I expected to open on the page I requested.

Screenshots

Screen Shot 2020-05-11 at 10 31 50 PM

Smartphone (please complete the following information):

  • Device: Android emulator Pixel 3a
  • OS: Android
  • Version : API 28

MahmoudAshours avatar May 11 '20 20:05 MahmoudAshours

and how many pages do you have in the document? in 3.6.0 problem with errorBuilder fixed can you copy the error code?

SergeShkurko avatar May 26 '20 04:05 SergeShkurko

Im having the same problem

copypasteearth avatar Jul 22 '20 20:07 copypasteearth

I am running into the same problem with the animateToPage method, it seems that the scroll controller is not getting attached to the scroll view when any jumping around pages is done. exception

Jonathan-Harty avatar Aug 09 '20 10:08 Jonathan-Harty

It seems that the _positions list on the _pageController on the _pdfController does not get items until after the onDocumentLoaded function is called leading to the _positions.isNotEmpty assertion to fail.

Jonathan-Harty avatar Aug 09 '20 12:08 Jonathan-Harty

According to the API, It seems to me that setting the initialPage parameter of the PdfController to >1 should cause the PDF to open at that page.

However this parameter seems to be ignored.

Looking into the code, I see that in the PdfController's _attach() method the initialPage is passed to _reInitPageController(), but not passed into _loadDocument(), which then calls _reInitPageController() again with an initialPage of 1 from its default parameter.

BrucesStuff avatar Aug 18 '20 00:08 BrucesStuff

I have already made a pull request that should fix the initialPage problem

Jonathan-Harty avatar Aug 18 '20 00:08 Jonathan-Harty

Yes i too found the same issue like @BrucesStuff commented. The initialPage params seems to be ignored.

rahulserver avatar Dec 27 '20 10:12 rahulserver