PDF does't render on Android but it works fine on web.
Simply try this HTML with below piece of Code on Android and you will see a black page as result. But you will see the PDF as you run app on Flutter Web. Tried these two versions but result is same: fwfh_webview: ^0.15.3 fwfh_webview: ^0.15.6
This HTML works perfectly on web but it displays a back page on Android. I have attached the Code sample below.
class PageContentEmbed extends StatelessWidget {
final String htmlString;
const PageContentEmbed(this.htmlString, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return HtmlWidget(
htmlString,
factoryBuilder: () => MyWidgetFactory(),
);
}
}
class MyWidgetFactory extends WidgetFactory with WebViewFactory {
// optional: override getter to configure how WebViews are built
@override
bool get webViewMediaPlaybackAlwaysAllow => true;
@override
String? get webViewUserAgent => 'My app';
}
###Attached screenshot of my web app where it works fine and same behaviour is expected on Android
###This is what I see on Android:
[✓] Flutter (Channel stable, 3.35.3, on macOS 26.0.1 25A362 darwin-arm64, locale en-PK) [244ms]
• Flutter version 3.35.3 on channel stable at /Users/niklas/Documents/sdks/3.35.3/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision a402d9a437 (5 weeks ago), 2025-09-03 14:54:31 -0700
• Engine revision ddf47dd3ff
• Dart version 3.9.2
• DevTools version 2.48.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-lldb-debugging
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0-rc1) [998ms]
• Android SDK at /Users/niklas/Library/Android/sdk
• Emulator version 35.3.11.0 (build_id 12836668) (CL:N/A)
• Platform android-36, build-tools 36.1.0-rc1
• ANDROID_HOME = /Users/niklas/Library/Android/sdk
• Java binary at: /Users/niklas/Library/Java/JavaVirtualMachines/corretto-17.0.14/Contents/Home/bin/java
This JDK is specified in your Flutter configuration.
To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment Corretto-17.0.14.7.1 (build 17.0.14+7-LTS)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 26.0.1) [942ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 17A400
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [7ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.2) [7ms]
• 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 21.0.4+-12422083-b607.1)
[✓] Connected device (3 available) [6.1s]
• V2249 (mobile) • 10FD8R02B40003D • android-arm64 • Android 15 (API 35)
• macOS (desktop) • macos • darwin-arm64 • macOS 26.0.1 25A362 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 141.0.7390.55
[✓] Network resources [974ms]
• All expected network resources are available.
• No issues found!
@daohoangson can you please check this issue?
Because Android WebView doesn't support PDF directly. You have to use Google Docs viewer or something similar
<iframe class="bespokely-embed" src="https://docs.google.com/gview?embedded=true&url=https://dm6lfrfdj0fil.cloudfront.net/attachments/attachments/000/000/471/original/Markdown_Support.pdf" frameborder="0" onmousewheel="" style="background:transparent;"></iframe>
Tried it but no change and seeing an exception in the logs
I/flutter (27961): PageContentEmbed.build <iframe class="bespokely-embed" src="https://docs.google.com/gview?embedded=true&url=https://dm6lfrfdj0fil.cloudfront.net/attachments/attachments/000/000/471/original/Markdown_Support.pdf" frameborder="0" onmousewheel="" width="392.72727272727275" height="848.7272727272727" style="background:transparent;"></iframe>
======== Exception caught by services library ======================================================
The following assertion was thrown during a platform message callback:
Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null, expected non-null DownloadListener.
'package:webview_flutter_android/src/android_webkit.g.dart':
Failed assertion: line 3924 pos 18: 'arg_pigeon_instance != null'
When the exception was thrown, this was the stack:
#2 DownloadListener.pigeon_setUpMessageHandlers.<anonymous closure> (package:webview_flutter_android/src/android_webkit.g.dart:3924:18)
#3 BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:259:49)
#4 _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:653:35)
#5 _invoke2 (dart:ui/hooks.dart:362:13)
#6 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
#7 _Channel._drainStep (dart:ui/channel_buffers.dart:229:31)
(elided 4 frames from class _AssertionError and dart:async)
====================================================================================================
======== Exception caught by services library ======================================================
The following assertion was thrown during a platform message callback:
Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onProgressChanged was null, expected non-null WebChromeClient.
'package:webview_flutter_android/src/android_webkit.g.dart':
Failed assertion: line 4439 pos 18: 'arg_pigeon_instance != null'
When the exception was thrown, this was the stack:
#2 WebChromeClient.pigeon_setUpMessageHandlers.<anonymous closure> (package:webview_flutter_android/src/android_webkit.g.dart:4439:18)
#3 BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:259:49)
#4 _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:653:35)
#5 _invoke2 (dart:ui/hooks.dart:362:13)
#6 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
#7 _Channel._drainStep (dart:ui/channel_buffers.dart:229:31)
(elided 4 frames from class _AssertionError and dart:async)
I run the app again and it worked 🥳. Thanks.