admob 0.1.27

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

Admob for Flutter

A GoogleAdmob plugin for Flutter. Currently supports interstitial ads in both iOS and Android.

Getting Started

The plugin contains two methods for loading and showing interstitial ads. In order to use them we must first import a couple of packages:

import 'package:admob/admob.dart';
import 'package:flutter/services.dart';
[iOS DEVELOPERS NOTE: Developed for Objective C. You cannot use 'use_frameworks' in your new project's podfile]

Interstitial Ads

Interstitial ads will display on both Android and iOS devices. In order to display our ads we need to pass Admob a few parameters. For more info on the app id and ad unit id visit http://google.com/admob.

String APP_ID = "Your APP ID";
String AD_UNIT_ID = "Your Ad_unit_id";
String DEVICE_ID = "Only necessary for testing: The device id you are testing with";
bool TESTING = A boolean declaring whether you are testing ads or live;

Async Methods

There are two asynchronous functions that we use, one to load the ad and one to show it.

The plugin's loadInterstitial method accepts an APP_ID, AD_UNIT_ID, DEVICE_ID, and TESTING. The loadInterstitial method should be called in an init method to load an ad as the app starts. After that the ads will reload themselves whenever you close the previous one. The plugin's showInterstitial method accepts no variables, and as the name implies shows the ad you loaded with loadInterstitial. If the ad is not yet loaded the showInterstitial method will return false.

@override
  initState(){
    super.initState();
    loadInterstitialAd();
  }
  
  loadInterstitialAd() async {
    bool loadResponse;
    try {
      loadResponse = await Admob.loadInterstitial(APP_ID, AD_UNIT_ID, DEVICE_ID, TESTING);
    } on PlatformException {
      loadResponse = false;
    }
    setState(() {
      _loadInterstitialResponse = loadResponse;
    });
  }

  showInterstitialAd() async {
    bool showResponse;
    try {
      showResponse = await Admob.showInterstitial;
    } on PlatformException {
      showResponse = false;
    }
    setState(() {
      _showInterstitialResponse = showResponse;
    });
  }

Now whenever we want to show the ad we simply call it:

showInterstitialAd()

An example of how to do that:

 @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Plugin example app'),
      ),
      body: new Center(child:new Text("$_showInterstitialResponse")),
      floatingActionButton: new FloatingActionButton(
        onPressed: () => showInterstitialAd(),
        child: new Icon(Icons.add),
      ),
    );
  }

View the example code included with the plugin in the example folder to see usage. The main.dart file included in the example folder shows an implementation of the plugin.

We currently have limited support for banner ads on the iOS platform. Banner ads work largely the same way as our interstitial do. Unlike interstitial there is no load function. Whenever we want a banner we simply call showBanner. The showBanner method accepts an extra variable over the loadInterstitial:

The important new variable is PLACEMENT. You should pass either "Top" or "Bottom" in this variable when displaying a banner ad. This declares where the ad will be shown.

  String APP_ID = "Your app id";
  String INTERSTITIAL_AD_UNIT_ID = "Your ad unit id";
  String DEVICE_ID = "(NOT REQD): Your device ID, to display test ads on a specific device";
  bool TESTING = A Boolean declaring whether ads should be live or testing;
  String PLACEMENT = "Top"

We are now left needing our async functions. We have two of them, showBanner and closeBanner, they return a string that can be described as a banner state. If the ad is shown properly it returns "ShowingTop" or "ShowingBottom" depending on placement or else it returns "NotShown". A banner does not have to be closed. It is simple an option for people looking to display one temporarily:

showBannerAd() async {
    var showResponse = "";
    try {showResponse = await Admob.showBanner(APP_ID, INTERSTITIAL_AD_UNIT_ID, DEVICE_ID, TESTING, PLACEMENT);}
    on PlatformException {showResponse = "Not Shown";}

    setState(() {
      _BannerState = showResponse;
    });
  }

  closeBannerAd() async {
    var showResponse = "";
    try {
      _BannerState = await Admob.closeBanner();
      print(_BannerState);
    } on PlatformException {
      showResponse = "Not Closed";
    }
    setState(() {
      _BannerState = showResponse;
    });
  }

SUPPORT THE DEVELOPER

BTC Address:13JN3yubwaPzyuBpj4MtKqirVfweq1b6Sc

Admob for Flutter

CHANGELOG

Version 0.1.27 - June 9th, 2017

[UPDATED]

Updated README to include iOS Notice

Version 0.1.26 - June 9th, 2017

[FIX]

Fixed pod install issue

Version 0.1.25 - June 6th, 2017

[UPDATED]

Updated main.dart example file to reflect changes

Version 0.1.24 - June 6th, 2017

[ADDED]

Added banner support for iOS devices, users can now display banners at the top or bottom of iOS apps [Android support in development]

[UPDATED]

Updated README to reflect iOS changes
Updated Changelog formatting

Version 0.1.23 - June 2nd, 2017

[ADDED]

Added Changelog

Version 0.1.22 - June 2nd, 2017

[CHANGED]

Updated podspec dependency for ios: will no longer throw missing module error

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:admob/admob.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var _showInterstitialResponse = "";
  var _loadInterstitialResponse = "";
  var _BannerState = "";

  String APP_ID = "ca-app-pub-9929690287684724~2116069294";
  String INTERSTITIAL_AD_UNIT_ID = "ca-app-pub-9929690287684724/7809349294";
  String DEVICE_ID = "FF18F6CCC658F56ECA4C4623DB5082CA";
  bool TESTING = true;
  String PLACEMENT = "Top";

  @override
  initState() {
    super.initState();
    loadInterstitialAd();
  }

  loadInterstitialAd() async {
    String loadResponse = "";
    try {
      loadResponse = await Admob.loadInterstitial(APP_ID, INTERSTITIAL_AD_UNIT_ID, DEVICE_ID, TESTING);
    } on PlatformException {
      loadResponse = "Failed to Load";
    }
    setState(() {
      _loadInterstitialResponse = loadResponse;
    });
  }

  showInterstitialAd() async {
    var showResponse = "";
    try {
      showResponse = await Admob.showInterstitial;
    } on PlatformException {
      showResponse = false;
    }
    setState(() {
      _showInterstitialResponse = showResponse;
    });
  }

  showBannerAd() async {
    var showResponse = "";
    try {showResponse = await Admob.showBanner(APP_ID, INTERSTITIAL_AD_UNIT_ID, DEVICE_ID, TESTING, PLACEMENT);}
    on PlatformException {showResponse = "Not Shown";}

    setState(() {
      _BannerState = showResponse;
    });
  }

  closeBannerAd() async {
    var showResponse = "";
    try {
      _BannerState = await Admob.closeBanner();
      print(_BannerState);
    } on PlatformException {
      showResponse = "Not Closed";
    }
    setState(() {
      _BannerState = showResponse;
    });
  }


  final List<String> _items = ['Interstitial','Top Banner', 'Bottom Banner'].toList();
  String _selection = "Interstitial";
  @override
  Widget build(BuildContext context) {

    final dropdownMenuOptions = _items.map((String item) =>
       new DropdownMenuItem<String>(value: item, child: new Text(item))
    ).toList();

    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Plugin example app'),
      ),
      body: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
                  new Text(_BannerState),
                  new DropdownButton<String>(
                  value: _selection,
                      items: dropdownMenuOptions,
                      onChanged: (s) {
                        setState(() {
                          _selection = s;
                          if(s == "Interstitial"){showInterstitialAd();}
                          if(s == "Top Banner"){
                            PLACEMENT = "Top";
                            if(_BannerState == "ShowingBottom"){closeBannerAd();}
                            if(_BannerState != "ShowingTop"){showBannerAd();}
                            else{closeBannerAd();}
                          }
                          if(s == "Bottom Banner"){
                            PLACEMENT = "Bottom";
                            if(_BannerState == "ShowingTop"){closeBannerAd();}
                            if(_BannerState != "ShowingBottom"){showBannerAd();}
                            else{closeBannerAd();}
                          }
                        });
                      }
                  )
            ]
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: () {
          print(_BannerState);
          if(_BannerState != "Shown"){showBannerAd();}
          else{closeBannerAd();}
        },
        child: new Icon(Icons.add),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  admob: ^0.1.27

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:admob/admob.dart';
  
Version Uploaded Documentation Archive
0.1.27 Jun 9, 2017 Go to the documentation of admob 0.1.27 Download admob 0.1.27 archive
0.1.26 Jun 9, 2017 Go to the documentation of admob 0.1.26 Download admob 0.1.26 archive
0.1.25 Jun 6, 2017 Go to the documentation of admob 0.1.25 Download admob 0.1.25 archive
0.1.24 Jun 6, 2017 Go to the documentation of admob 0.1.24 Download admob 0.1.24 archive
0.1.23 Jun 2, 2017 Go to the documentation of admob 0.1.23 Download admob 0.1.23 archive
0.1.22 Jun 2, 2017 Go to the documentation of admob 0.1.22 Download admob 0.1.22 archive
0.1.21 Jun 2, 2017 Go to the documentation of admob 0.1.21 Download admob 0.1.21 archive
0.1.2 Jun 2, 2017 Go to the documentation of admob 0.1.2 Download admob 0.1.2 archive
0.1.1 Jun 2, 2017 Go to the documentation of admob 0.1.1 Download admob 0.1.1 archive
0.1.0 Jun 2, 2017 Go to the documentation of admob 0.1.0 Download admob 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
63
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
32
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Health issues and suggestions

Document public APIs (-10 points)

6 out of 6 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-50 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Homepage is not helpful. (-10 points)

Update the homepage property: create a website about the package or use the source repository URL.

Package is getting outdated. (-49.04 points)

The package was released 77 weeks ago.

The description is too short. (-20 points)

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8