flutter_pdf_render icon indicating copy to clipboard operation
flutter_pdf_render copied to clipboard

Example request for Texture

Open mfizz1 opened this issue 2 years ago • 0 comments

It is a bit beyond me and I cannot figure out what it is that I am doing or how to go about it. I want to utilize the PdfPageImageTexture.

I am trying to get the PDF and create a slideshow of all the pages. Whilst I can achieve that using just PDF view, it want to make it as efficient as possible.


Future<List<int>> pdfToTexids(String url) async {
  final file = await DefaultCacheManager().getSingleFile(url);
  final doc = await PdfDocument.openFile(file.path);
  final int pages = doc.pageCount;
  final List<int> imageTexids = [];

  for (var i = 1; i <= pages; i++) {
    final imageTexture =
        await PdfPageImageTexture.create(pdfDocument: doc, pageNumber: i);
    imageTexids.add(imageTexture.texId);
    imageTexture.dispose();
  }
  doc.dispose();
  return imageTexids;
}

I use this inside a Future Builder like this:

 Widget build(BuildContext context) {
    return FutureBuilder(
      future: pdfToTexids(
          "example.pdf.com"),
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          return Texture(
            textureId: snapshot.data!.elementAt(1),
            freeze: true,
          );
        } else {
          return const SizedBox();
        }
      },
    );

  }

I only get a black box with the notification in debuG console for:

E/IMGSRV ( 463): :0: IsTextureConsistent: IMGEGLImage is not consistent

What am I doing wrong?

mfizz1 avatar Apr 29 '23 21:04 mfizz1