easy_admob_ads_flutter 0.0.3 copy "easy_admob_ads_flutter: ^0.0.3" to clipboard
easy_admob_ads_flutter: ^0.0.3 copied to clipboard

A simple and flexible Flutter package to integrate AdMob ad formats with minimal setup.

Stand With Palestine

Easy AdMob Integration for Flutter #

pub package Last Commit Pull Requests Code Size License

Show some ❤️ by giving the repo a ⭐ and liking 👍 the package on pub.dev!

Features #

This package simplifies integrating multiple AdMob ad formats in your Flutter apps, including:

  • Banner
  • Interstitial
  • Rewarded
  • Rewarded Interstitial
  • App Open Ads
  • Native Ads

Also includes built-in support for GDPR consent using Google's User Messaging Platform (UMP), ensuring compliance in GDPR-affected regions.

Getting Started #

To get started with easy_admob_ads_flutter, follow the steps below to integrate AdMob ads into your Flutter app.

1. Install the package #

Add the dependency in your pubspec.yaml:

dependencies:
  easy_admob_ads_flutter: ^<latest_version>

Replace <latest_version> with the latest version on pub.dev

OR install it directly via terminal:

flutter pub add easy_admob_ads_flutter

2. Configure platform-specific AdMob setup #

Android

  • Open your android/app/src/main/AndroidManifest.xml
  • Add your AdMob App ID inside the <application> tag:
<meta-data
  android:name="com.google.android.gms.ads.APPLICATION_ID"
  android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

iOS

  • Open your ios/Runner/Info.plist and add:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>

3. Initialize the SDK and pass your Ad Unit IDs #

Inside your main.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize ad unit IDs for Android and/or iOS (required for at least one)
  AdIdRegistry.initialize(
    ios: {
      AdType.banner: "ca-app-pub-ios-banner",
      AdType.interstitial: "ca-app-pub-ios-interstitial",
      AdType.rewarded: "ca-app-pub-ios-rewarded",
      AdType.rewardedInterstitial: "ca-app-pub-ios-rewarded-int",
      AdType.appOpen: "ca-app-pub-ios-appopen",
      AdType.native: "", // Leave empty to skip a specific type
    },
    android: {
      AdType.banner: "ca-app-pub-android-banner",
      AdType.interstitial: "ca-app-pub-android-interstitial",
      AdType.rewarded: "ca-app-pub-android-rewarded",
      AdType.rewardedInterstitial: "ca-app-pub-android-rewarded-int",
      AdType.appOpen: "ca-app-pub-android-appopen",
      AdType.native: "", // Leave empty to skip a specific type
    },
  );

  // Optional: configure ad visibility
  AdHelper.showAds = true;
  AdHelper.showAppOpenAds = true;

  // Simulate GDPR consent (debug only, false in release)
  AdHelper.showConstentGDPR = true;

  // Initialize Google Mobile Ads
  await AdmobService().initialize();

  runApp(const MyApp());
}

See the full example in the example/ folder of this repository for complete usage of all ad types with interactive UI.

Usage #

After initializing AdMob and registering your ad unit IDs, you can use the following widgets and classes to display ads:

AdmobBannerAd(adSize: AdSize(width: screenWidth, height: 120))

Native Ad #

AdmobNativeAd.medium()

Interstitial Ad #

final interstitialAd = AdmobInterstitialAd();
interstitialAd.loadAd();
interstitialAd.showAd();

Rewarded Ad #

final rewardedAd = AdmobRewardedAd(
  onRewardEarned: (reward) {
    // Grant the user a reward
  },
);
rewardedAd.loadAd();
rewardedAd.showAd();

Rewarded Interstitial Ad #

final rewardedInterstitialAd = AdmobRewardedInterstitialAd(
  onRewardEarned: (reward) {
    // Grant reward here
  },
);
rewardedInterstitialAd.loadAd();
rewardedInterstitialAd.showAd();

App Open Ad #

final appOpenAd = AdmobAppOpenAd();
appOpenAd.loadAd();
appOpenAd.showAdIfAvailable();

You can also control when App Open ads show automatically using: AdHelper.showAppOpenAds = true;

final consentManager = ConsentManager();

// Request consent on app launch
consentManager.gatherConsent((error) {
  if (error != null) {
    debugPrint('Consent error: ${error.errorCode} - ${error.message}');
  } else {
    debugPrint('Consent successfully gathered');
  }
});

// Optionally show Privacy Options UI (if required)
consentManager.showPrivacyOptionsForm((error) {
  if (error != null) {
    debugPrint('Privacy form error: ${error.errorCode} - ${error.message}');
  }
});

This ensures GDPR compliance using Google’s User Messaging Platform (UMP). Use AdHelper.showConstentGDPR = true in debug builds to simulate consent for testing.

Author #

Huzaib Sayyed

GitHub LinkedIn

5
likes
0
points
137
downloads

Publisher

verified publisherstudygyaan.com

Weekly Downloads

A simple and flexible Flutter package to integrate AdMob ad formats with minimal setup.

Repository (GitHub)
View/report issues

Topics

#admob #ads #google-mobile-ads #google-admob-flutter #monetization

License

unknown (license)

Dependencies

flutter, google_mobile_ads, shared_preferences

More

Packages that depend on easy_admob_ads_flutter