1

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");
                },
             );
          }),
        );
      }
    }
2
  • You need to do this first WebView.shouldOverrideUrlLoading = true just before runApp is called in main.dart pub.dev/documentation/flutter_inappwebview/latest/…
    – Rahul
    Aug 4, 2021 at 9:11
  • @Rahul that property is not defined for the class WebView, besides is already set to true in cross platform options and it works for normal links, but not for pdfs Aug 4, 2021 at 10:09

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.