sosnus
sosnus

Reputation: 1380

Flutter how to open pdf using web browser

How to open pdf from url address in flutter? I try call window like this: enter image description here

And select there application for open pdf file. I try do it using libraries:

But none of them cannot do it. Any ideas or samples?

Upvotes: 0

Views: 756

Answers (1)

Kaushik Chandru
Kaushik Chandru

Reputation: 17812

You can force webview using

Future<void> _launchInBrowser(Uri url) async {
    if (!await launchUrl(
      url,
      mode: LaunchMode.externalApplication,
    )) {
      throw 'Could not launch $url';
    }
  }

or to load it in an inapp web view

Future<void> _launchInWebViewOrVC(Uri url) async {
    if (!await launchUrl(
      url,
      mode: LaunchMode.inAppWebView,
      webViewConfiguration: const WebViewConfiguration(
          headers: <String, String>{'my_header_key': 'my_header_value'}),
    )) {
      throw 'Could not launch $url';
    }
  }

Upvotes: 1

Related Questions