adblocker_webview 2.0.0 copy "adblocker_webview: ^2.0.0" to clipboard
adblocker_webview: ^2.0.0 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:flutter/material.dart';

import 'browser_screen.dart';
import 'url_input_section.dart';

void main() async {
  await AdBlockerWebviewController.instance.initialize(
    FilterConfig(
      filterTypes: [FilterType.easyList, FilterType.adGuard],
    ),
    [],
  );
  runApp(const ExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AdBlocker WebView Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool _shouldBlockAds = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AdBlocker WebView Example'),
        actions: [
          Row(
            children: [
              const Text('Block Ads'),
              Switch(
                value: _shouldBlockAds,
                onChanged: (value) {
                  setState(() {
                    _shouldBlockAds = value;
                  });
                },
              ),
            ],
          ),
        ],
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                const Text(
                  'Enter a URL to test ad blocking',
                  style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 16),
                UrlInputSection(
                  onUrlSubmitted: (url) {
                    Navigator.of(context).push(
                      MaterialPageRoute<void>(
                        builder: (context) => BrowserScreen(
                          url: url,
                          shouldBlockAds: _shouldBlockAds,
                        ),
                      ),
                    );
                  },
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
19
likes
150
points
124
downloads

Publisher

verified publisherislamdidarmd.dev

Weekly Downloads

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

adblocker_manager, flutter, webview_flutter

More

Packages that depend on adblocker_webview