firebase_admob 0.0.2

  • Example
  • Installing
  • Versions
  • 93


A plugin for Flutter that supports loading and displaying banner and interstitial (full-screen) ads using the Firebase AdMob API.

Warning: This plugin is still under development, some AdMob features are not available yet and testing has been limited. Feedback and Pull Requests are welcome.


Before showing an ad the plugin must be initialized with an AdMob app id:

FirebaseAdMob.instance.initialize(appId: appId);

Ads must be created with an AdMob unit id and they can include targeting information:

MobileAdTargetingInfo targetingInfo = new MobileAdTargetingInfo(
  keywords: <String>['foo', 'bar'],
  contentUrl: '',
  birthday: new,
  childDirected: true,
  gender: "male", // or "female", "unknown"

BannerAd myBanner = new BannerAd(
  unitId: myBannerAdUnitId,
  targetingInfo: targetingInfo,

InterstitialAd myInterstitial = new InterstitialAd(
  unitId: myInterstitalAdUnitId,
  targetingInfo: targetingInfo,

Ads must be loaded before they're shown.

  ..load() // typically this happens well before the ad is shown;
// InterstitialAds are loaded and shown in the same way

Ads can be disposed to free up plugin resources. Disposing a banner ad that's been shown removes it from the screen. Interstitial ads can't be programatically removed from view.

Ads can be created with a MobileAdEvent listener. The listener can be used to detect when the ad has actually finished loading (or failed to load at all).


This is just an initial version of the plugin. There are still some limitiations:

  • Banner ads always appear at the bottom of the screen, they can't be positioned or animated into view.
  • It's not possible to specify a banner ad's size.
  • There's no support for rewarded video ads or native ads
  • The existing tests are fairly rudimentary.
  • There is no API doc
  • The example should demonstrate how to show gate a route push with an interstitial ad

For Flutter plugins for other Firebase products, see


  • Change GMS dependency to 11.+


  • Initial Release: not ready for production use


// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:firebase_admob/firebase_admob.dart';

// A placeholder AdMob App Id for testing.
const String appId = 'ca-app-pub-3940256099942544~3347511713';

// Specify this to quiet Android log messages that say:
//   Use AdRequest.Builder.addTestDevice("...") to get test ads on this device.
//const String testDevice = null;
const String testDevice = '33B6FA56617D7688A3A466295DED82BE';

// See
const String bannerAdUnitId = 'ca-app-pub-3940256099942544/6300978111';
const String interstitialAdUnitId = 'ca-app-pub-3940256099942544/1033173712';

class MyApp extends StatefulWidget {
  _MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {
  static final MobileAdTargetingInfo targetingInfo = new MobileAdTargetingInfo(
    testDevices: testDevice != null ? <String>[testDevice] : null,
    keywords: <String>['foo', 'bar'],
    contentUrl: '',
    birthday: new,
    childDirected: true,
    gender: MobileAdGender.male,

  BannerAd _bannerAd;
  InterstitialAd _interstitialAd;

  BannerAd createBannerAd() {
    return new BannerAd(
      unitId: bannerAdUnitId,
      targetingInfo: targetingInfo,
      listener: (MobileAdEvent event) {
        print("BannerAd event $event");

  InterstitialAd createInterstitialAd() {
    return new InterstitialAd(
      unitId: interstitialAdUnitId,
      targetingInfo: targetingInfo,
      listener: (MobileAdEvent event) {
        print("InterstitialAd event $event");

  void initState() {
    FirebaseAdMob.instance.initialize(appId: appId);
    _bannerAd = createBannerAd()..load();

  void dispose() {

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('AdMob Plugin example app'),
        body: new Center(
          child: new Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              new RaisedButton(
                  child: const Text('SHOW BANNER'),
                  onPressed: () {
                    _bannerAd ??= createBannerAd();
              new RaisedButton(
                  child: const Text('REMOVE BANNER'),
                  onPressed: () {
                    _bannerAd = null;
              new RaisedButton(
                child: const Text('SHOW INTERSTITIAL'),
                onPressed: () {
                  _interstitialAd = createInterstitialAd()
            ].map((Widget button) {
              return new Padding(
                padding: const EdgeInsets.symmetric(vertical: 16.0),
                child: button,

void main() {
  runApp(new MyApp());

1. Depend on it

Add this to your package's pubspec.yaml file:

  firebase_admob: "^0.0.2"

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:firebase_admob/firebase_admob.dart';
Version Uploaded Documentation Archive
0.3.1 Feb 15, 2018 Go to the documentation of firebase_admob 0.3.1 Download firebase_admob 0.3.1 archive
0.3.0 Jan 23, 2018 Go to the documentation of firebase_admob 0.3.0 Download firebase_admob 0.3.0 archive
0.2.3 Jan 12, 2018 Go to the documentation of firebase_admob 0.2.3 Download firebase_admob 0.2.3 archive
0.2.2 Jan 4, 2018 Go to the documentation of firebase_admob 0.2.2 Download firebase_admob 0.2.2 archive
0.2.1 Jan 4, 2018 Go to the documentation of firebase_admob 0.2.1 Download firebase_admob 0.2.1 archive
0.2.0 Jan 4, 2018 Go to the documentation of firebase_admob 0.2.0 Download firebase_admob 0.2.0 archive
0.1.0 Dec 20, 2017 Go to the documentation of firebase_admob 0.1.0 Download firebase_admob 0.1.0 archive
0.0.3 Dec 14, 2017 Go to the documentation of firebase_admob 0.0.3 Download firebase_admob 0.0.3 archive
0.0.2 Oct 17, 2017 Go to the documentation of firebase_admob 0.0.2 Download firebase_admob 0.0.2 archive


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1
  • Flutter: 0.0.22


Describes how popular the package is relative to other packages. [more]
86 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
flutter 0.0.0
meta ^1.0.4 1.1.1 1.1.2
platform ^2.0.0 2.1.1
Transitive dependencies
async 2.0.3
charcode 1.1.1
collection 1.14.5
http 0.11.3+16
http_parser 3.1.1
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.4 1.1.5
vector_math 2.0.5
Dev dependencies
mockito ^2.0.2
test 0.12.21