firebase_admob 0.9.0+10

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

firebase_admob #

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

For Flutter plugins for other Firebase products, see

AndroidManifest changes #

AdMob 17 requires the App ID to be included in the AndroidManifest.xml. Failure to do so will result in a crash on launch of your app. The line should look like:


where [ADMOB_APP_ID] is your App ID. You must pass the same value when you initialize the plugin in your Dart code.

See for more information about configuring AndroidManifest.xml and setting up your App ID.

Info.plist changes #

Admob 7.42.0 requires the App ID to be included in Info.plist. Failure to do so will result in a crash on launch of your app. The lines should look like:


where [ADMOB_APP_ID] is your App ID. You must pass the same value when you initialize the plugin in your Dart code.

See for more information about configuring Info.plist and setting up your App ID.

Initializing the plugin #

The AdMob plugin must be initialized with an AdMob App ID.

FirebaseAdMob.instance.initialize(appId: appId);

Android #

Starting in version 17.0.0, if you are an AdMob publisher you are now required to add your AdMob app ID in your AndroidManifest.xml file. Once you find your AdMob app ID in the AdMob UI, add it to your manifest adding the following tag:

        <!-- TODO: Replace with your real AdMob app ID -->

Failure to add this tag will result in the app crashing at app launch with a message starting with "The Google Mobile Ads SDK was initialized incorrectly."

On Android, this value must be the same as the App ID value set in your AndroidManifest.xml.

iOS #

Starting in version 7.42.0, you are required to add your AdMob app ID in your Info.plist file under the Runner directory. You can add it using Xcode or edit the file manually:


Failure to add this tag will result in the app crashing at app launch with a message including "GADVerifyApplicationID."

Using banners and interstitials #

Banner and interstitial ads can be configured with target information. And in the example below, the ads are given test ad unit IDs for a quick start.

MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
  keywords: <String>['flutterio', 'beautiful apps'],
  contentUrl: '',
  childDirected: false,
  designedForFamilies: false,
  gender: MobileAdGender.male, // or MobileAdGender.female, MobileAdGender.unknown
  testDevices: <String>[], // Android emulators are considered test devices

BannerAd myBanner = BannerAd(
  // Replace the testAdUnitId with an ad unit id from the AdMob dash.
  adUnitId: BannerAd.testAdUnitId,
  size: AdSize.smartBanner,
  targetingInfo: targetingInfo,
  listener: (MobileAdEvent event) {
    print("BannerAd event is $event");

InterstitialAd myInterstitial = InterstitialAd(
  // Replace the testAdUnitId with an ad unit id from the AdMob dash.
  adUnitId: InterstitialAd.testAdUnitId,
  targetingInfo: targetingInfo,
  listener: (MobileAdEvent event) {
    print("InterstitialAd event is $event");

Ads must be loaded before they're shown.

  // typically this happens well before the ad is shown
    // Positions the banner ad 60 pixels from the bottom of the screen
    anchorOffset: 60.0,
    // Positions the banner ad 10 pixels from the center of the screen to the right
    horizontalCenterOffset: 10.0,
    // Banner Position
    anchorType: AnchorType.bottom,
    anchorType: AnchorType.bottom,
    anchorOffset: 0.0,
    horizontalCenterOffset: 0.0,

BannerAd and InterstitialAd objects can be disposed to free up plugin resources. Disposing a banner ad that's been shown removes it from the screen. Interstitial ads, however, can't be programmatically removed from view.

Banner and interstitial 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).

Using rewarded video ads #

Unlike banners and interstitials, rewarded video ads are loaded one at a time via a singleton object, RewardedVideoAd.instance. Its load method takes an AdMob ad unit ID and an instance of MobileAdTargetingInfo:

RewardedVideoAd.instance.load(myAdMobAdUnitId, targetingInfo);

To listen for events in the rewarded video ad lifecycle, apps can define a function matching the RewardedVideoAdListener typedef, and assign it to the listener instance variable in RewardedVideoAd. If set, the listener function will be invoked whenever one of the events in the RewardedVideAdEvent enum occurs. After a rewarded video ad loads, for example, the RewardedVideoAdEvent.loaded is sent. Any time after that, apps can show the ad by calling show:;

When the AdMob SDK decides it's time to grant an in-app reward, it does so via the RewardedVideoAdEvent.rewarded event:

RewardedVideoAd.instance.listener =
    (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
  if (event == RewardedVideoAdEvent.rewarded) {
    setState(() {
      // Here, apps should update state to reflect the reward.
      _goldCoins += rewardAmount;

Because RewardedVideoAd is a singleton object, it does not offer a dispose method.

Limitations #

This plugin currently has some limitations:

  • Banner ads cannot be animated into view.
  • It's not possible to specify a banner ad's size.
  • There's no support for 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

Issues and feedback #

Please file Flutterfire specific issues, bugs, or feature requests in our issue tracker.

Plugin issues that are not specific to Flutterfire can be filed in the Flutter issue tracker.

To contribute a change to this plugin, please review our contribution guide, and send a pull request.

0.9.0+10 #

  • Remove the deprecated author: field from pubspec.yaml
  • Migrate the plugin to the pubspec platforms manifest.
  • Bump the minimum Flutter version to 1.10.0.

0.9.0+9 #

  • Updated README instructions for contributing for consistency with other Flutterfire plugins.

0.9.0+8 #

  • Remove AndroidX warning.

0.9.0+7 #

  • Update Android gradle plugin, gradle, and Admob versions.
  • Improvements to the Android implementation, fixing warnings about a possible null pointer exception.
  • Fixed an issue where an advertisement could incorrectly remain displayed when transitioning to another screen.

0.9.0+6 #

  • Remove duplicate example from documentation.

0.9.0+5 #

  • Update documentation to reflect new repository location.

0.9.0+4 #

  • Add the ability to horizontally adjust the ads banner location by specifying a pixel offset from the centre.

0.9.0+3 #

  • Update google-services Android gradle plugin to 4.3.0 in documentation and examples.

0.9.0+2 #

  • On Android, no longer crashes when registering the plugin if no activity is available.

0.9.0+1 #

  • Add missing template type parameter to invokeMethod calls.
  • Bump minimum Flutter version to 1.5.0.

0.9.0 #

  • Update Android dependencies to latest.

0.8.0+4 #

  • Update documentation to add AdMob App ID in Info.plist
  • Add iOS AdMob App ID in Info.plist in example project

0.8.0+3 #

  • Log messages about automatic configuration of the default app are now less confusing.

0.8.0+2 #

  • Remove categories.

0.8.0+1 #

  • Log a more detailed warning at build time about the previous AndroidX migration.

0.8.0 #

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.7.0 #

  • Mark Dart code as deprecated where the newer version AdMob deprecates features (Birthday, Gender, and Family targeting).
  • Update gradle dependencies.
  • Add documentation for new AndroidManifest requirements.

0.6.1+1 #

  • Bump Android dependencies to latest.
  • THIS WAS AN UNINTENTIONAL BREAKING CHANGE. Users should consume 0.6.1 instead if they need the old API, or 0.7.0 for the bumped version.
  • Guide how to fix crash with admob version 17.0.0 in README

0.6.1 #

  • listener on MobileAd shouldn't be final.
  • Ad listeners can to be set in or out of Ad initialization.

0.6.0 #

  • Add nonPersonalizedAds option to MobileAdTargetingInfo

0.5.7 #

  • Bumped mockito dependency to pick up Dart 2 support.

0.5.6 #

  • Bump Android and Firebase dependency versions.

0.5.5 #

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.5.4+1 #

  • Graduate to beta.

0.5.4 #

  • Fixed a bug that was causing rewarded video failure event to be called on the wrong listener.

0.5.3 #

  • Updated Google Play Services dependencies to version 15.0.0.
  • Added handling of rewarded video completion event.

0.5.2 #

  • Simplified podspec for Cocoapods 1.5.0, avoiding link issues in app archives.

0.5.1 #

  • Fixed Dart 2 type errors.

0.5.0 #

  • Breaking change. The BannerAd constructor now requires an AdSize parameter. BannerAds can be created with AdSize.smartBanner, or one of the other predefined AdSize values. Previously BannerAds were always defined with the smartBanner size.

0.4.0 #

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.3.2 #

  • Fixed Dart 2 type errors.

0.3.1 #

  • Enabled use in Swift projects.

0.3.0 #

  • Added support for rewarded video ads.
  • Breaking change. The properties and parameters named "unitId" in BannerAd and InterstitialAd have been renamed to "adUnitId" to better match AdMob's documentation and UI.

0.2.3 #

  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.

0.2.2 #

  • Added platform-specific App IDs and ad unit IDs to example.
  • Separated load and show functionality for interstitials in example.

0.2.1 #

  • Use safe area layout to place ad in iOS 11

0.2.0 #

  • Breaking change. MobileAd TargetingInfo requestAgent is now hardcoded to 'flutter-alpha'.

0.1.0 #

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.
  • Relaxed GMS dependency to [11.4.0,12.0[

0.0.3 #

  • Add FLT prefix to iOS types
  • Change GMS dependency to 11.4.+

0.0.2 #

  • Change GMS dependency to 11.+

0.0.1 #

  • Initial Release: not ready for production use


firebase_admob_example #

Demonstrates how to use the firebase_admob plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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

  firebase_admob: ^0.9.0+10

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub 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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
meta ^1.0.4 1.1.8
platform ^2.0.0 2.2.1
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
firebase_core ^0.4.0
mockito ^3.0.0