I am creating an app using flutter. I am struggling to open the Portable Document Format inside the web view using flutter. Please help to resolve this
body: SafeArea( child: WebView(
initialUrl: pdf filePath, javascriptMode: JavascriptMode.unrestricted, onWebViewCreated: (WebViewController webViewController) { _webViewController = webViewController; _webViewController.clearCache(); _webViewController.reload(); }, ), ),
my code
SafeArea( child: WebView( initialUrl: filePath, javascriptMode:
JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) { _webViewController = webViewController;
_webViewController.clearCache();
_webViewController.reload(); }, ), ),
I was facing the same issue before and I used this method to solve that. In the initialUrl you can check if the url is a pdf link and use google doc to open it.
initialUrl: widget.link!.indexOf('.pdf') != -1 ? 'https://docs.google.com/gview?
embedded=true&url=${widget.link}'
: widget.link!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With