iOS 15 - App crashes after tapping cancel and then tapping button to launch print screen
Describe the bug
App crashes after initially tapping the elevated button to build/print the PDF file and launch to the print screen, then tapping cancel on the print screen, and then tapping the elevated button to launch to the print screen the build/print PDF again.
This seems to only occur when trying to convertHTML method that is described in the readme, the other examples/methods seems to work as intended. Additionally this issue has only presented itself with iOS 15, older versions such as iOS 12-14 are/were working
To Reproduce
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Colors.blueGrey[800],
textStyle: TextStyle(color: Colors.white)
),
onPressed: () async {
await Printing.layoutPdf(
dynamicLayout: false,
onLayout: (PdfPageFormat format) async => await Printing.convertHtml(
format: format,
html: '<html><body><p>Hello!</p></body></html>',
),
);
},
icon: Icon(Icons.picture_as_pdf),
label: Semantics(child: Text('Print' ),
),
),
Expected behavior
The user to be able to print, cancel, repeat with no crashes.
Flutter Doctor
[✓] Flutter (Channel stable, 2.8.0, on macOS 12.0.1 21A559 darwin-x64, locale en-CA)
• Flutter version 2.8.0 at /Users/wraithshroud/AndroidStudioProjects/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision cf44000065 (9 days ago), 2021-12-08 14:06:50 -0800
• Engine revision 40a99c5951
• Dart version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/wraithshroud/Library/Android/sdk
• Platform android-30, build-tools 29.0.2
• ANDROID_HOME = /Users/wraithshroud/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio 3.6.3.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.48.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (2 available)
• HC SC Web’s iPhone X (mobile) • iOS 15.2 19C56
• Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110
• No issues found!
Desktop (please complete the following information):
- [x] iOS
Smartphone (please complete the following information):
- Device: iPhone X
- OS: i0S 15.1 and 15.2
I second that. A print that works flawlessly on Android just did the same for me on iOS (simulator, I don't have a real device). The print preview page appears but no preview, just the controls at the top. It becomes totally unresponsive, no Cancel, nothing, I have to use the Simulator menu to press Home and kill the whole app. Same input here, a HTML, in my case nothing fancy, the body only has some tables with some texts in it.
Actually, I'm not familiar with debugging on macOS and the Simulator. I'd be glad to look for some debug output (like Logcat on Android) if possible...
I believe I have sorted out the issue now. Within the PrintJob.swift file at line 78 printInfo.outputType = .general seems to be the culprit causing the issue.
Wrapping this in a DispatchQueue resolves the problem and is working correctly for me:
DispatchQueue.main.async { printInfo.outputType = .general }
@jelen-HC That is quite strange. Apple... Can you create a PR?
I second that. A print that works flawlessly on Android just did the same for me on iOS (simulator, I don't have a real device). The print preview page appears but now preview, just the controls at the top. It becomes totally unresponsive, no Cancel, nothing, I have to use the Simulator menu to press home and kill the whole app. Same input here, a HTML, in my case nothing fancy, the body only has some tables with some texts in it.
Actually, I'm not familiar with debugging on macOS and the Simulator. I'd be glad to look for some debug output (like Logcat on Android) if possible...
@deakjahn I am not sure if it is the same issue or not, it sounds more like a previous issue on the iOS side of things but I could be mistaken. Make sure you have added the dynamicLayout: false attribute (if you haven't) or things will not work correctly on the iOS side of things.
See my original post for as to where to access/add it.
@DavBfr Strange indeed! I should be able to create a PR shortly.
Does this mean you identified the problem? Could you describe it shortly?
Oh, I can see your next comment. I'm on my phone now. I'll try as soon as I get back to the computer.
I can confirm that dynamicLayout: false solves the immediate problem. Still, the PR is most welcome, of course. :-)
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Closing this stale issue because it has no activity.