'how to open the pdf document inside web view using flutter

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(); }, ), ),


Solution 1:[1]

Try this:

import 'dart: html' as html;
html.window.open ('http: ///www.website.com/document.pdf');

You can refer: https://pub.dev/packages/pdf

Solution 2:[2]

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!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Divyesh_08
Solution 2 Dare Oloruntoba