Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter AdBlock WebView?

Tags:

flutter

dart

Is there a way to block ads in an flutter WebView? I am building app that lets users browse web pages, but need to block ads. Its basically a custom browser, but I need to get rid of ads.

like image 371
fluttery Avatar asked May 15 '19 23:05

fluttery


People also ask

What is flutter_WebView_plugin?

It’s a Flutter plugin that allows you to incorporate WebView widgets into your Flutter app, to use headless WebViews, or to use In-App browsers. So, what’s the difference between webview_flutter (Official flutter plugin) and flutter_webview_plugin ?

How to call flutter_inappwebview callhandler from a JavaScript event?

In order to call window.flutter_inappwebview.callHandler (handlerName <String>, ...args) properly, you need to wait and listen to the JavaScript event flutterInAppWebViewPlatformReady. This event will be dispatched as soon as the platform (Android or iOS) is ready to handle the callHandler method.

How to implement Adblock in Android Studio?

How to implement: 1 Implement Adblock.java into your Project 2 Create a raw folder in Android Studio ( {projectname}appsrcmainresraw) 3 Add filterlists to raw folder More ...

What events does the inappwebview widget offer?

The InAppWebView widget offers a variety of events! Here’s a few of them: onLoadHttpError: event fired when the WebView main page receives an HTTP error; onConsoleMessage: event fired when the WebView receives a JavaScript console message (such as console.log , console.error , etc.);


1 Answers

navigationDelegate: (NavigationRequest request) { return NavigationDecision.prevent;}

I added that to the Webview to prevent navigation to other screens in case they accidentally click on those ads.

WebView(
      initialUrl: widget.url,
      javascriptMode: JavascriptMode.unrestricted,
      onWebViewCreated: (WebViewController webViewController) {
        _controller.complete(webViewController);
      },
      javascriptChannels: <JavascriptChannel>[
        _toasterJavascriptChannel(context),
      ].toSet(),
      navigationDelegate: (NavigationRequest request) {
        return NavigationDecision.prevent;
     
      },
      onPageStarted: (String url) {
        print('Page started loading: $url');
      },
      onPageFinished: (String url) {
        print('Page finished loading: $url');
      },
      gestureNavigationEnabled: true,
    );
like image 132
Prince Kelvin Avatar answered Nov 11 '22 14:11

Prince Kelvin