首页 > 解决方案 > Flutter Webview 的广告拦截器

问题描述

我使用 webview_flutter 插件制作了一个应用程序,webviews 指向一个流式传输视频的 url。但是每次我进入这个网页视图时都会弹出一个新的广告。如果有人能提供解决方案来防止这种情况发生,我会很高兴。我在此处添加了代码,并且正在使用 NavigationDecision.prevent 来禁止广告将我带到新页面。

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebViewExample extends StatefulWidget {
  @override
  WebViewExampleState createState() => WebViewExampleState();
}

class WebViewExampleState extends State<WebViewExample> {
  @override
  void initState() {
    super.initState();
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

  @override
  Widget build(BuildContext context) {
    return WebView(
      initialUrl: "https://streamani.net/streaming.php?id=MTA4NjM4&title=Boruto%3A+Naruto+Next+Generations&typesub=SUB&sub=&cover=Y292ZXIvYm9ydXRvLW5hcnV0by1uZXh0LWdlbmVyYXRpb25zLnBuZw==",
      javascriptMode: JavascriptMode.unrestricted,
      navigationDelegate: (NavigationRequest request) {
        return NavigationDecision.prevent;
      } ,

    );
  }
}

标签: androidflutterdartwebviewadblock

解决方案


推荐阅读