firebase_admob 0.2.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 95

firebase_admob

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.

Using

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: 'http://foo.com/bar.html',
  birthday: new DateTime.now(),
  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.

myBanner
  ..load() // typically this happens well before the ad is shown
  ..show();
// 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).

Limitations

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 FlutterFire.md.

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

example/lib/main.dart

// 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 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:firebase_admob/firebase_admob.dart';

// A placeholder AdMob App Id for testing. AdMob App IDs and ad unit IDs are
// specific to a single operating system, so apps building for both Android and
// iOS will need a set for each platform.
const String androidAppId = 'ca-app-pub-3940256099942544~3347511713';
const String iOSAppId = 'ca-app-pub-3940256099942544~1458002511';

// These are AdMob's test ad unit IDs, which always return test ads. You're
// encouraged to use them for testing in your own apps.
const String androidBannerAdUnitId = 'ca-app-pub-3940256099942544/6300978111';
const String androidInterstitialAdUnitId =
    'ca-app-pub-3940256099942544/1033173712';
const String iOSBannerAdUnitId = 'ca-app-pub-3940256099942544/2934735716';
const String iOSInterstitialAdUnitId = 'ca-app-pub-3940256099942544/4411468910';

// You can also test with your own ad unit IDs by registering your device as a
// test device. Check the logs for your device's ID value.
const String testDevice = 'YOUR_DEVICE_ID';

class MyApp extends StatefulWidget {
  @override
  _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: 'http://foo.com/bar.html',
    birthday: new DateTime.now(),
    childDirected: true,
    gender: MobileAdGender.male,
  );

  BannerAd _bannerAd;
  InterstitialAd _interstitialAd;

  BannerAd createBannerAd() {
    return new BannerAd(
      unitId: Platform.isAndroid ? androidBannerAdUnitId : iOSBannerAdUnitId,
      targetingInfo: targetingInfo,
      listener: (MobileAdEvent event) {
        print("BannerAd event $event");
      },
    );
  }

  InterstitialAd createInterstitialAd() {
    return new InterstitialAd(
      unitId: Platform.isAndroid
          ? androidInterstitialAdUnitId
          : iOSInterstitialAdUnitId,
      targetingInfo: targetingInfo,
      listener: (MobileAdEvent event) {
        print("InterstitialAd event $event");
      },
    );
  }

  @override
  void initState() {
    super.initState();
    FirebaseAdMob.instance
        .initialize(appId: Platform.isAndroid ? androidAppId : iOSAppId);
    _bannerAd = createBannerAd()..load();
  }

  @override
  void dispose() {
    _bannerAd?.dispose();
    _interstitialAd?.dispose();
    super.dispose();
  }

  @override
  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(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              new RaisedButton(
                  child: const Text('SHOW BANNER'),
                  onPressed: () {
                    _bannerAd ??= createBannerAd();
                    _bannerAd
                      ..load()
                      ..show();
                  }),
              new RaisedButton(
                  child: const Text('REMOVE BANNER'),
                  onPressed: () {
                    _bannerAd?.dispose();
                    _bannerAd = null;
                  }),
              new RaisedButton(
                child: const Text('LOAD INTERSTITIAL'),
                onPressed: () {
                  _interstitialAd?.dispose();
                  _interstitialAd = createInterstitialAd()..load();
                },
              ),
              new RaisedButton(
                child: const Text('SHOW INTERSTITIAL'),
                onPressed: () {
                  _interstitialAd?.show();
                },
              ),
            ].map((Widget button) {
              return new Padding(
                padding: const EdgeInsets.symmetric(vertical: 16.0),
                child: button,
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}

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

1. Depend on it

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


dependencies:
  firebase_admob: "^0.2.3"

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.5.3 Apr 18, 2018 Go to the documentation of firebase_admob 0.5.3 Download firebase_admob 0.5.3 archive
0.5.2 Apr 11, 2018 Go to the documentation of firebase_admob 0.5.2 Download firebase_admob 0.5.2 archive
0.5.1 Apr 9, 2018 Go to the documentation of firebase_admob 0.5.1 Download firebase_admob 0.5.1 archive
0.5.0 Mar 20, 2018 Go to the documentation of firebase_admob 0.5.0 Download firebase_admob 0.5.0 archive
0.4.0 Mar 9, 2018 Go to the documentation of firebase_admob 0.4.0 Download firebase_admob 0.4.0 archive
0.3.2 Mar 1, 2018 Go to the documentation of firebase_admob 0.3.2 Download firebase_admob 0.3.2 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

All 15 versions...

Analysis

We analyzed this package on Apr 9, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.46.0
  • pana: 0.10.6
  • Flutter: 0.2.9

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
91 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
95
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • 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.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run flutter format to format lib/firebase_admob.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
flutter 0.0.0
meta ^1.0.4 1.1.2
platform ^2.0.0 2.1.2
Transitive dependencies
collection 1.14.6 1.14.9
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.5 2.0.6
Dev dependencies
flutter_test
mockito ^2.0.2