Open deibeeed opened 1 week ago
Hi.
I resolved the issue by manually calling the web implementation of the printing library and checking if the application is running on web platform using kIsWeb
from foundations.dart
package.
The web implementation of printing.layoutPdf
is found in package:printing/printing_web.dart
.
import 'package:printing/printing.dart';
import 'package:printing/printing_web.dart';
.
.
.
if (kIsWeb) {
return PrintingPlugin().layoutPdf(
null,
// [onLayout] will be called multiple times
// when the user changes the printer or printer settings
(PdfPageFormat format) {
return _buildPdf(
PdfPageFormat.a4,
...
);
},
'print',
PdfPageFormat.a4,
true,
true,
OutputType.generic,
false,
);
}
return Printing.layoutPdf(
// [onLayout] will be called multiple times
// when the user changes the printer or printer settings
onLayout: (PdfPageFormat format) {
return _buildPdf(
PdfPageFormat.a4,
... );
},
);
The implementation is very hacky but it gets the job done. I was able to show print preview on web.
I'm not sure how to address or where the issue really is but I believe that there's an issue on how the printing for a certain platform is called, and I believe this is where the issue starts.
file: pubspec.yaml
flutter:
plugin:
platforms:
android:
package: net.nfet.flutter.printing
pluginClass: PrintingPlugin
ios:
pluginClass: PrintingPlugin
linux:
pluginClass: PrintingPlugin
macos:
pluginClass: PrintingPlugin
web:
fileName: printing_web.dart
pluginClass: PrintingPlugin
windows:
pluginClass: PrintingPlugin
Maintainer, contributors, If you think the issue doesn't make sense, please feel free to close the issue. I'll keep the issue open because I believe the issue is worth checking for.
Thank you for the great package! It really helped me in a lot of my projects that requires print capabilities.
cc: @DavBfr
Hi. Help needed.
I am building a app that supports web. Pdf creation and printing works fine on local development but when I build the app for release, the UI gets stuck and from the console log, I receive this error:
pdf and printing versions:
Flutter command to build for web:
fvm flutter build web -t lib/main_development.dart --release --dart-define=ENVIRONMENT=development --output build/web/development --web-renderer canvaskit
result from
fvm flutter doctor -v
Hoping that someone could show me the ropes.
Update
I was able to narrow down the issue to the printing library. I tried deploying to hosting a version that does not call
Printing.layoutPdf()
and the pdf was saved, no issues were thrown by the browser.Again, I hope that someone can show me the ropes.. Thank you in advance!