facebook_audience_network 0.4.0

facebook_audience_network #

Pub GitHub Awesome Flutter

Facebook Audience Network plugin for Flutter applications.

Note: Currently only Android platform is supported.

Banner AdNative Banner AdNative Ad
Banner AdNative Banner AdNative Ad
Interstitial AdRewarded Video AdIn-Stream Video Ad
Interstitial AdRewarded AdInStream Ad

Getting Started #

1. Initialization: #

For testing purposes you need to obtain the hashed ID of your testing device. To obtain the hashed ID:

  1. Call FacebookAudienceNetwork.init() during app initialization.
  2. Place the FacebookBannerAd widget in your app.
  3. Run the app.

The hased id will be in printed to the logcat. Paste that onto the testingId parameter.

FacebookAudienceNetwork.init(
  testingId: "37b1da9d-b48c-4103-a393-2e095e734bd6",
);

2. Show Banner Ad: #

Container(
  alignment: Alignment(0.5, 1),
  child: FacebookBannerAd(
    placementId: "YOUR_PLACEMENT_ID",
    bannerSize: BannerSize.STANDARD,
    listener: (result, value) {
      switch (result) {
        case BannerAdResult.ERROR:
          print("Error: $value");
          break;
        case BannerAdResult.LOADED:
          print("Loaded: $value");
          break;
        case BannerAdResult.CLICKED:
          print("Clicked: $value");
          break;
        case BannerAdResult.LOGGING_IMPRESSION:
          print("Logging Impression: $value");
          break;
      }
    },
  ),
)

3. Show Interstitial Ad: #

FacebookInterstitialAd.loadInterstitialAd(
  placementId: "YOUR_PLACEMENT_ID",
  listener: (result, value) {
    if (result == InterstitialAdResult.LOADED)
      FacebookInterstitialAd.showInterstitialAd(delay: 5000);
  },
);

4. Show Rewarded Video Ad: #

FacebookRewardedVideoAd.loadRewardedVideoAd(
  placementId: "YOUR_PLACEMENT_ID",
  listener: (result, value) {
    if(result == RewardedVideoResult.LOADED)
      FacebookRewardedVideoAd.showRewardedVideoAd();
    if(result == RewardedVideoResult.VIDEO_COMPLETE)
      print("Video completed");
  },
);

5. Show In-Stream Video Ad: #

Make sure the width and height is 300 at minimum.

FacebookInStreamVideoAd(
  placementId: "YOUR_PLACEMENT_ID",
  height: 300,
  listener: (result, value) {
    if (result == InStreamVideoAdResult.VIDEO_COMPLETE) {
      setState(() {
        _videoComplete = true;
      });
    }
  },
)

6. Show Native Ad: #

FacebookNativeAd(
  placementId: "YOUR_PLACEMENT_ID",
  adType: NativeAdType.NATIVE_AD,
  width: double.infinity,
  height: 300,
  backgroundColor: Colors.blue,
  titleColor: Colors.white,
  descriptionColor: Colors.white,
  buttonColor: Colors.deepPurple,
  buttonTitleColor: Colors.white,
  buttonBorderColor: Colors.white,
  listener: (result, value) {
    print("Native Ad: $result --> $value");
  },
),

7. Show Native Banner Ad: #

Use NativeBannerAdSize to choose the height for Native banner ads. height property is ignored for native banner ads.

FacebookNativeAd(
  placementId: "YOUR_PLACEMENT_ID",
  adType: NativeAdType.NATIVE_BANNER_AD,
  bannerAdSize: NativeBannerAdSize.HEIGHT_100,
  width: double.infinity,
  backgroundColor: Colors.blue,
  titleColor: Colors.white,
  descriptionColor: Colors.white,
  buttonColor: Colors.deepPurple,
  buttonTitleColor: Colors.white,
  buttonBorderColor: Colors.white,
  listener: (result, value) {
    print("Native Ad: $result --> $value");
  },
),

Check out the example for complete implementation.

Future Work #

Implement for iOS platform.

0.4.0 #

  • Upgraded to AndroidX #22

0.3.3 #

  • Add Native Ad On Load Success & Dynamic Height

0.3.2 #

  • Added keepalive
  • Bumped build.gradle version to 3.3.1

0.3.1 #

  • Updated ReadMe

0.3.0 #

  • Implemented Native Ad & Native Banner Ad

0.2.0 #

  • Implemented in-stream video ad.
  • Implemented Rewarded video Ad
  • Added key parameter to banner ad widget.
  • Fixed an issue where banner ad was not getting displayed when listener callback was not implemented by the user.
  • Now the banner ad is no longer destroyed when widget is disposed.

0.1.1 #

  • MIT License

0.1.0 #

  • Implemeted Banner & Interstitial Ad for Android

0.0.1 #

  • TODO: Describe initial release.

example/README.md

facebook_audience_network_example #

Demonstrates how to use the facebook_audience_network plugin.

Banner AdNative Banner AdNative Ad
Banner AdNative Banner AdNative Ad
Interstitial AdRewarded Video AdIn-Stream Video Ad
Interstitial AdRewarded AdInStream Ad

Use this package as a library

1. Depend on it

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


dependencies:
  facebook_audience_network: ^0.4.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:facebook_audience_network/facebook_audience_network.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
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]
91
Learn more about scoring.

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

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/ad/ad_banner.dart. (-1 points)

Analysis of lib/ad/ad_banner.dart reported 2 hints:

line 91 col 10: This method overrides a method annotated as @mustCallSuper in 'AutomaticKeepAliveClientMixin', but doesn't invoke the overridden method.

line 133 col 34: This function has a return type of 'Future', but doesn't end with a return statement.

Fix lib/ad/ad_native.dart. (-1 points)

Analysis of lib/ad/ad_native.dart reported 2 hints:

line 124 col 10: This method overrides a method annotated as @mustCallSuper in 'AutomaticKeepAliveClientMixin', but doesn't invoke the overridden method.

line 184 col 34: This function has a return type of 'Future', but doesn't end with a return statement.

Fix lib/ad/ad_instream.dart. (-0.50 points)

Analysis of lib/ad/ad_instream.dart reported 1 hint:

line 107 col 34: This function has a return type of 'Future', but doesn't end with a return statement.

Format lib/constants.dart.

Run flutter format to format lib/constants.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test