adblocker_webview 0.1.4 copy "adblocker_webview: ^0.1.4" to clipboard
adblocker_webview: ^0.1.4 copied to clipboard

A webview for flutter with adblocking capability. It's currently based on Flutter InAppWebview Plugin.

example/lib/main.dart

import 'package:adblocker_webview/adblocker_webview.dart';
import 'package:example/browser.dart';
import 'package:example/url_input.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _adBlockerWebviewController = AdBlockerWebviewController.instance;
  bool _showBrowser = false;
  bool _shouldBlockAds = false;
  String _url = "";

  @override
  void initState() {
    super.initState();
    _adBlockerWebviewController.initialize();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      floatingActionButton: _showBrowser
          ? FloatingActionButton(
              child: const Icon(Icons.edit),
              onPressed: () {
                setState(() {
                  _showBrowser = false;
                });
              },
            )
          : null,
      body: _showBrowser
          ? Browser(
              url: _url,
              controller: _adBlockerWebviewController,
              shouldBlockAds: _shouldBlockAds,
            )
          : UrlInput(
              onSubmit: (url) {
                setState(() {
                  _url = url;
                  _showBrowser = true;
                });
              },
              onBlockAdsStatusChange: (shouldBlockAds) {
                setState(() {
                  _shouldBlockAds = shouldBlockAds;
                });
              },
              shouldBlockAds: _shouldBlockAds,
            ),
    );
  }
}
16
likes
140
pub points
73%
popularity

Publisher

verified publisherislamdidarmd.dev

A webview for flutter with adblocking capability. It's currently based on Flutter InAppWebview Plugin.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_inappwebview, get_it, http

More

Packages that depend on adblocker_webview