Skip to content

A webview implementation of in Flutter that blocks most of the ads that appear inside of the webpages

License

Notifications You must be signed in to change notification settings

islamdidarmd/flutter_adblocker_webview

Repository files navigation

style: very good analysis

  • A webview implementation of in Flutter that blocks most of the ads that appear inside of the webpages
  • Current implementation is based on official flutter_inappwebview packages. So, the features and limitation of that package is included

On iOS the WebView widget is backed by a WKWebView. On Android the WebView widget is backed by a WebView.

Android iOS
Support SDK 19+ or 20+ 11.0+

Getting started

Add adblocker_webview as a dependency in your pubspec.yaml file.

Usage

  1. Acquire an instance of AdBlockerWebviewController
  final _adBlockerWebviewController = AdBlockerWebviewController.instance;

It's better to warm up the controller before displaying the webview. It's possible to do that by

  @override
  void initState() {
    super.initState();
    _adBlockerWebviewController.initialize();
    /// ... Other code here.
  }
  1. Add the AdBlockerWebview in widget tree
        AdBlockerWebview(
            url: "Valid url Here",
            adBlockerWebviewController: widget.controller,
            onProgress: (progress) {
              setState(() {
                _progress = progress;
              });
            },
            shouldBlockAds: true,
            /// Other params if required
          );

Supported params of AdBlockerWebview are:

const AdBlockerWebview({
      required this.adBlockerWebviewController,
      required this.shouldBlockAds,
      this.url,
      this.initialHtmlData,
      this.onLoadStart,
      this.onLoadFinished,
      this.onProgress,
      this.onLoadError,
      this.onTitleChanged,
      this.options,
      this.additionalHostsToBlock = const [],
      super.key,
      }) : assert(
          (url == null && initialHtmlData != null) ||
          (url != null && initialHtmlData == null),
          'Both url and initialHtmlData can not be non null');

Caching

  • API response for Ad hosts is cached automatically and no config is required!

Contribution

Contributions are welcome 😄. Please file an issue here if you want to include additional feature or found a bug!

Guide

  1. Create an issue first to make sure your request is not a duplicate one
  2. Create a fork of the repository (If it's your first contribution)
  3. Make a branch from develop
  4. Branch name should indicate the contribution type
  • feature/** for new feature
  • bugfix/** for a bug fix
  1. Raise a PR against the develop branch