ScerIO / packages.flutter

👨‍💻 Plugins and packages for Flutter framework
https://pub.dev/publishers/serge.software/packages
MIT License
461 stars 453 forks source link

page take a noticeable time to load #47

Closed Fethi-Hamdani closed 4 years ago

Fethi-Hamdani commented 4 years ago

when the pdf file is loaded pages takes time to load even in release which is pretty annoying for book readers and it is even worse for pages that contain images, is there any to make it faster?

emreesen27 commented 4 years ago

Do you use FutureBuilder ?

Fethi-Hamdani commented 4 years ago

yes, i copied the example

Fethi-Hamdani commented 4 years ago

the pdf file i'm trying to display is from device's storage not assets, can that be the issue?

emreesen27 commented 4 years ago

I don't think there is a problem with this. I use a similar method and I have no performance issues. I must mention that I am working on large pdf files.

!!! You should try the release version for full performance.

PDFDocument _document;

Future<PDFDocument> _getDocument() async {
return _document = await PDFDocument.openFile(your path+ "/file.pdf"); }

FutureBuilder<PDFDocument>( future: _getDocument(), builder: (_, snapshot) { if(snapshot.hasdata) { return PDFView()... } } )

SergeShkurko commented 4 years ago

@Fethi1 where you run project? On real device in debug mod or emulator in debug mode?

Fethi-Hamdani commented 4 years ago

i run it on a real device, i have tried it on both debug and release and in different phones and the same thing happen, especially for pages that has images, it takes some time to load. the app i'm developing is supposed to fetch pdf files on device and display each file on a new Route

SergeShkurko commented 4 years ago

You can play with render option (render docs)

PDFView(
  controller: pageController,
  renderer: (PDFPage page) => page.render(
    // for example set to 1.25-1.5
    // the quality of the final result may decrease
    width: page.width * 2,
    height: page.height * 2,
    format: PDFPageFormat.JPEG,
    backgroundColor: '#FFFFFF',
  ),
);

pages are converted to an image and part of the time is spent on transfer from dart side to platform and back

atheist1 commented 4 years ago

@SergeShkurko it seems converted page to an image spent lots of time when i use animateToPage or other animation api .There is a black area on the bottom.what should i do to solve the problem?

deakjahn commented 4 years ago

@SergeShkurko please change the example as I described in https://github.com/rbcprolabs/packages.flutter/issues/46#issuecomment-615361536

You shouldn't load the PDF this way into a FutureBuilder. This results in many repeated calls to the function and is discouraged in the Flutter documentation (yes, I know it's cached in a variable but still, this is not the suggested way of handling it).

SergeShkurko commented 4 years ago

@atheist1 usage jumpTo or minimize delay

SergeShkurko commented 4 years ago

@deakjahn i change api un 3.0.0, it is no longer required

SergeShkurko commented 4 years ago

option renderer was not working until 3.0.0, now fixed