admob_flutter 0.2.0

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

Announcement: I'm looking for a maintainer #

I'm really sorry to announce this, but my schedules have been too tight for me the last months that I can't find good time to maintain this project. I'm looking for a possible maintainer to transfer this project to, someone who is sure to perfectly handle it and keep it updated. Please drop me a message on youssef.kbe@gmail.com.

admob_flutter #

version version

Demo

A new Flutter plugin that uses native platform views to show Admob banner ads!

This plugin also has support for Interstitial and Reward ads.

This is an early version of the plugin, my primary goal was to overcome the banner ads positioning limitations by implementing a platform views solution, and keeping things simple and stupid because I'm still learning about many Flutter related stuff. I will actively work on adding missing features, improving, and refactoring the code in my free time.

Currently working on Android only, but iOS support will be available so soon.

Installation #

Add this to your pubspec.yml dependencies:

admob_flutter: "^0.1.2"

How to use #

Update your AndroidManifest.xml #

Add your AdMob App ID to your app's AndroidManifest.xml file by adding the <meta-data> tag shown below. You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.

You can use this test App ID from Admob for development:

ca-app-pub-3940256099942544~3347511713
<manifest>
  <application>
    <meta-data
      android:name="com.google.android.gms.ads.APPLICATION_ID"
      android:value="ca-app-pub-3940256099942544~3347511713"/>
  </application>
</manifest>

Initialize the plugin #

First thing to do before attempting to show any ads is to initialize the plugin. You can do this in the earliest starting point of your app, your main function:

import 'package:admob_flutter/admob_flutter.dart';

void main() {
  Admob.initialize('ca-app-pub-3940256099942544~3347511713');
  runApp(MyApp());
}

Showing Banner Ads #

This plugin uses Native Platform Views to show Admob banner ads thus, same as any other widget, there's no limitations on where to place your banners.

AdmobBanner(
  adUnitId: 'ca-app-pub-3940256099942544/6300978111',
  adSize: AdmobBannerSize.BANNER,
)

The plugin provides all banner sizes supported by Admob, and will wrap the banner with a correctly sized Container so you don't worry about your ad displaying incorrectly:

  • AdmobBannerSize.Banner: 320x50
  • AdmobBannerSize.LARGE_BANNER: 320x100
  • AdmobBannerSize.MEDIUM_RECTANGLE: 300x250
  • AdmobBannerSize.FULL_BANNER: 468x60
  • AdmobBannerSize.LEADERBOARD: 728x90
  • AdmobBannerSize.SMART_BANNER: Wrap in a container with a size of your choice

Listening to Banner Ads events #

You can attach a listener to your ads in order to customize their behavior like this:

AdmobBanner(
  adUnitId: 'ca-app-pub-3940256099942544/6300978111',
  adSize: AdmobBannerSize.BANNER,
  listener: (AdmobAdEvent event, Map<String, dynamic> args) {
    switch (event) {
      case AdmobAdEvent.loaded:
        print('Admob banner loaded!');
        break;

      case AdmobAdEvent.opened:
        print('Admob banner opened!');
        break;

      case AdmobAdEvent.closed:
        print('Admob banner closed!');
        break;

      case AdmobAdEvent.failedToLoad:
        print('Admob banner failed to load. Error code: ${args['errorCode']}');
        break;
    }
  }
)

Showing Interstitial Ads #

// First, create an interstitial ad
AdmobInterstitial interstitialAd = AdmobInterstitial(
  adUnitId: 'ca-app-pub-3940256099942544/1033173712',
);

// Interstitials must be loaded before shown.
// Make sure to always load them ahead so they can be
// available to be shown immediately to the user
interstitialAd.load();

// Check if the ad is loaded and then show it
if (await interstitialAd.isLoaded) {
  interstitialAd.show();
}

// Finally, make sure you dispose the ad if you're done with it
interstitialAd.dispose();

Listening to Interstitial Ads events #

Same as banner ads, you can attach a listener to interstitials too. For example if you wish to:

  • Show the interstitial as soon as it is loaded
  • Load a new ad and show it as soon as the old one is closed
  • Get your users stuck in an interstitial ads loop to maximize revenue
  • Get your Admob account banned and lose all your earnings

You can do something like this (Don't do it!):

AdmobInterstitial interstitialAd;

interstitialAd = AdmobInterstitial(
  adUnitId: 'ca-app-pub-3940256099942544/1033173712',
  listener: (AdmobAdEvent event, Map<String, dynamic> args) {
    if (event == AdmobAdEvent.loaded) interstitialAd.show();
    if (event == AdmobAdEvent.closed) interstitialAd.load();
    if (event == AdmobAdEvent.failedToLoad) {
      // Start hoping they didn't just ban your account :)
      print("Error code: ${args['errorCode']}");
    }
  },
);

Showing Reward Ads #

// First, create a reward ad
AdmobReward rewardAd = AdmobReward(
  adUnitId: 'ca-app-pub-3940256099942544/5224354917',
);

// Reward ads must be loaded before shown.
// Make sure to always load them ahead so they can be
// available to be shown immediately to the user
rewardAd.load();

// Check if the ad is loaded and then show it
if (await rewardAd.isLoaded) {
  rewardAd.show();
}

// Finally, make sure you dispose the ad if you're done with it
rewardAd.dispose();

Listening to Reward Ads events #

Listening to reward ads events works the same as with banners and interstitials, except that rewards have some additional events. One of them is the rewarded event which you should listen to so you know whether your users have earned the reward or not:

AdmobReward rewardAd = AdmobReward(
  adUnitId: 'ca-app-pub-3940256099942544/5224354917',
  listener: (AdmobAdEvent event, Map<String, dynamic> args) {
    if (event == AdmobAdEvent.rewarded) {
      print('User was rewarded!');
      print('Reward type: ${args['type']}');
      print('Reward amount: ${args['amount']}');
    }
  },
);

Showing Native Ads #

Coming soon!

Using targeting info #

Coming soon!

[0.2.0] - 2019/04/04

Update to AndroidX.

[0.1.2] - Dec 10

  • Release first version

example/README.md

admob_flutter_example #

Demonstrates how to use the admob_flutter plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  admob_flutter: ^0.2.0

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:admob_flutter/admob_flutter.dart';
  
Version Uploaded Documentation Archive
0.2.0 Apr 16, 2019 Go to the documentation of admob_flutter 0.2.0 Download admob_flutter 0.2.0 archive
0.1.2 Dec 10, 2018 Go to the documentation of admob_flutter 0.1.2 Download admob_flutter 0.1.2 archive
0.1.1 Dec 10, 2018 Go to the documentation of admob_flutter 0.1.1 Download admob_flutter 0.1.1 archive
0.1.0 Dec 10, 2018 Go to the documentation of admob_flutter 0.1.0 Download admob_flutter 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
90
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on May 23, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.16
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-0.48 points)

56 out of 57 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/admob_event_handler.dart. (-0.50 points)

Analysis of lib/src/admob_event_handler.dart reported 1 hint:

line 11 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/admob_interstitial.dart. (-0.50 points)

Analysis of lib/src/admob_interstitial.dart reported 1 hint:

line 25 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/admob_reward.dart. (-0.50 points)

Analysis of lib/src/admob_reward.dart reported 1 hint:

line 25 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Format lib/src/admob_banner.dart.

Run flutter format to format lib/src/admob_banner.dart.

Format lib/src/admob_banner_controller.dart.

Run flutter format to format lib/src/admob_banner_controller.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.6 1.1.7
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8