DavBfr / dart_pdf

Pdf creation module for dart/flutter
https://pub.dev/packages/pdf
Apache License 2.0
1.39k stars 616 forks source link

Printing a PDF with layoutPdf fails to print: The 'net.nfet.printing' channel sent a message from native to Flutter on a non-platform thread #1638

Open AndyWerder opened 5 months ago

AndyWerder commented 5 months ago

Describe the bug Re-testing a custom action in FlutterFlow that generates a PDF using the packages pdf and printing packages, I realize that the PDF gets generated but I cannot view it on my iOS devices. The custom action also stores the PDF in Google storage and that file can be viewed, so I'm certain that the PDF got properly generated. This has worked perfectly a few weeks ago and now no longer does, so must be an incompatibility with either an iOS change or a Flutter or new package version incompatibility. Note that the PDF still opens in Android, so it does not look like it's a generic Flutter (or FlutterFlow) issue. Versions used: pdf: ^3.10.7, printing: ^5.11.1 (5.12.0 makes no difference). The error thrown in iOS produces a few lines in the Xcode console: [ERROR:flutter/shell/common/shell.cc(1038)] The 'net.nfet.printing' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel. See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.

Expected behavior Upon invoking the Printing.layout method (see code above), the iOS (or Android) print dialog appears. At this point the user can choose to print or cancel or whatever the PDF document. A thumbnail of the document should be visible within the dialog box but it is missing in iOS (while still present in Android). Selecting Print in iOS does not print the PDF.

To Reproduce Code snippet to reproduce the behavior: final Uint8List pdfData = await report.buildPdf(PdfPageFormat.letter); await Printing.layoutPdf(onLayout: (PdfPageFormat format) async => pdfData);

Screenshots 85C99F98-FFEC-499A-B37D-7B0FCA229174_1_201_a

Flutter Doctor andreaswerder@Andreass-M3-MacBook-Pro a_p_test_app % flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.19.4, on macOS 14.4.1 23E224 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.1) [✓] VS Code (version 1.87.2) [✓] Connected device (4 available) [✓] Network resources

• No issues found!

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

mohanedsayed commented 3 months ago

Hello @AndyWerder, I am facing the same problem currently, did you find any sort of a work around ?

SkyeCodesThings commented 3 weeks ago

Bump, I'm facing the same issue

JennyFieldings12 commented 3 weeks ago

I ran into this same issue today as well.

AndyWerder commented 3 weeks ago

I'm using FlutterFlow so I chose a FF based alternative. It's pretty straightforward - instead of using the printing package, you save the PDF in a data store (I'm using Firestore and Google storage), then launch the PDF file once the file has been written from there. Launching a file using the platform-specific ecosystem gives you all you need to forward the PDF to mail, printer or even save it locally. I can give you a more specific answer for the Flutterflow case if that also applies to you, for a native Dart/Flutter app you'd have to adjust the approach. Let me know.