简体   繁体   中英

Is there AdMob support for Flutter web?

Is there AdMob support for Flutter web? All libraries that I found are intended only for Android and IOS

As you can see in the image below, Google Admobe is not supported for the web so you can not use it for flutter web or other web frameworks.

Admobe面板

On other hand, you can use adsense and set your ads for flutter web, and I find this solution for using Adsense as HTML(with IFrameElement)

first created an html file adview.html

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:inline-block;width:320px;height:80px"
     data-ad-client="ca-pub-xxxxxx"
     data-ad-slot="xxxxxxx"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

And then, an IFrameElement to make use of the HTML:

import 'dart:html';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';

Widget adsenseAdsView() {
  // ignore: undefined_prefixed_name
  ui.platformViewRegistry.registerViewFactory(
      'adViewType',
      (int viewID) => IFrameElement()
        ..width = '320'
        ..height = '100'
        ..src = 'adview.html'
        ..style.border = 'none');

  return SizedBox(
    height: 100.0,
    width: 320.0,
    child: HtmlElementView(
      viewType: 'adViewType',
    ),
  );
}

firebase_admob is now deprecated in favour of google_mobile_ads and both of them do not support flutter web. However, you can use display ads on websites using Google Adsense.

You can create a blank web page and add ads and embed the flutter app in the HTML page.

Ref:

Google Adsense

Embed flutter App in website

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM