Fariz Mamedow
Fariz Mamedow

Reputation: 189

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

Upvotes: 18

Views: 7578

Answers (2)

Ali Azimoshan
Ali Azimoshan

Reputation: 1361

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

Admob panel

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

First create 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',
    ),
  );
}

Upvotes: 7

Nishuthan S
Nishuthan S

Reputation: 1735

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

Upvotes: 3

Related Questions