ScerIO / packages.flutter

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

An unhandleable error is thrown when attempting to display unsupported files, such as password-protected PDFs #504

Open chocoyama opened 5 months ago

chocoyama commented 5 months ago

Describe the bug When attempting to display a password-protected PDF file using the pdfx library in a Flutter application, the app fails to load the document and throws the following error instead:

════════ Exception caught by image resource service ════════════════════════════
The following PlatformException was thrown resolving an image codec:
PlatformException(RENDER_ERROR, Unexpected error: renderer is nil., null, null)

When the exception was thrown, this was the stack:
#0      PdfxApi.getPage (package:pdfx/src/renderer/io/pigeon.dart:647:7)
pigeon.dart:647
<asynchronous suspension>
#1      PdfDocumentPigeon.getPage.<anonymous closure> (package:pdfx/src/renderer/io/platform_pigeon.dart:99:24)
platform_pigeon.dart:99
<asynchronous suspension>
#2      BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
basic_lock.dart:33
<asynchronous suspension>
#3      _PdfViewState._getPageImage.<anonymous closure> (package:pdfx/src/viewer/simple/pdf_view.dart:121:22)
pdf_view.dart:121
<asynchronous suspension>
#4      BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
basic_lock.dart:33
<asynchronous suspension>
#5      PdfPageImageProvider._loadAsync (package:pdfx/src/viewer/pdf_page_image_provider.dart:44:32)
pdf_page_image_provider.dart:44
<asynchronous suspension>
#6      MultiFrameImageStreamCompleter._handleCodecReady (package:flutter/src/painting/image_stream.dart:985:3)
image_stream.dart:985
<asynchronous suspension>

Page: 0, DocumentId: 9E53B1E8-D4EC-4FB2-A368-07DB67BBC315

The PdfView interface provides onDocumentError and errorBuilder methods, but these are not triggered in this case, leaving no way to handle the error within the application.

To Reproduce Steps to reproduce the behavior:

  1. Integrate the pdfx library into a Flutter project.
  2. Attempt to open a password-protected PDF file using PdfView.
  3. Observe that the document fails to load and the specified error is thrown.
  4. Note that onDocumentError and errorBuilder are not called, even though an error has occurred.

Expected behavior I expect the pdfx library to provide an interface or mechanism to explicitly catch and handle errors like this. The library should enable developers to implement error handling through an interface or callback function specifically designed to manage these types of errors when rendering fails.

Screenshots

Smartphone (please complete the following information): I've only confirmed this on iOS, but it doesn't seem to be device-dependent.

Additional context