flutter inAppWebview: reacting to click on pdf link

Issue

I’m trying to use InAppWebview plugin in flutter, works well but when I click on a pdf link it does nothing.

to try that just click on the first or second link in the google search.

nor shouldOverrideUrlLoading or onDownloadStart

any idea on how to show or how to intercept it?

    class WebViewWidget extends StatefulWidget {
      final String url;
    
      WebViewWidget(this.url);
    
      @override
      _WebViewWidgetState createState() => _WebViewWidgetState();
    }
    
    class _WebViewWidgetState extends State<WebViewWidget> {
      final Completer<InAppWebViewController> _controller =
          Completer<InAppWebViewController>();
    
      final InAppWebViewGroupOptions _options = InAppWebViewGroupOptions(
        crossPlatform: InAppWebViewOptions(
          useShouldOverrideUrlLoading: true,
          mediaPlaybackRequiresUserGesture: false,
          javaScriptEnabled: true,
        ),
        android: AndroidInAppWebViewOptions(
          useHybridComposition: true,
          loadWithOverviewMode: true,
          useWideViewPort: false,
          builtInZoomControls: false,
          domStorageEnabled: true,
          supportMultipleWindows: true,
        ),
      );
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Builder(builder: (BuildContext context) {
            return InAppWebView(
                initialUrlRequest: URLRequest(url: Uri.parse("https://www.google.com/search?client=firefox-b-d&q=pdf+example")),
                initialOptions: _options,
                shouldOverrideUrlLoading: (controller, action) {
                  print("override");
                  return Future.value(NavigationActionPolicy.ALLOW);
                },
                onWebViewCreated: (webViewController) {
                  _controller.complete(webViewController);
                },
                onDownloadStart: (controller, uri) {
                  print("download");
                },
             );
          }),
        );
      }
    }

Solution

To onDownloadStart to be called useOnDownloadStart: true must be set on crossPlatform: InAppWebViewOptions(). Once that was done the callback was called correctly.

Answered By – jack_the_beast

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.