flutter_admobs_handler 1.1.5
flutter_admobs_handler: ^1.1.5 copied to clipboard
Reusable AdMob utilities for Flutter with banner, interstitial, and rewarded ads, test/production switching, and a central AppAdsUtil configuration API.
flutter_admobs_handler #
Reusable AdMob utilities for Flutter with banner, interstitial, and rewarded
ads, a central AppAdsUtil configuration API, and safe test/production
switching.
Built on google_mobile_ads
^9.1.0 (compatible with Dart 3.10+ / Flutter 3.38+, including Gradle 9).
Features #
- Banner, interstitial, and rewarded ad utilities
- Drop-in adaptive banner widget
AppAdsUtilsingleton with setters/getters for all ad unit IDs- Global test/production switch
- Automatic fallback to Google test ad units when IDs are missing
- Test device registration for safe production-unit testing
- Publisher mismatch logging at startup
- Banner retry support for transient
NO_FILLresponses - Structured
RewardedAdShowResultfor reliable reward tracking
Platform support #
| Platform | Supported |
|---|---|
| Android | Yes |
| iOS | Yes |
| Web | No |
| Desktop | No |
Installation #
Add to pubspec.yaml:
dependencies:
flutter_admobs_handler: ^1.1.2
Then run:
flutter pub get
Native setup #
Declare your AdMob application ID in the platform manifests. This is different from ad unit IDs and must belong to the same AdMob account.
Android — android/app/src/main/AndroidManifest.xml inside <application>:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY" />
iOS — ios/Runner/Info.plist:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY</string>
While testing you can use Google's sample application IDs from AdMobAdsConstants.androidTestApplicationId and AdMobAdsConstants.iosTestApplicationId.
Quick start #
import 'package:flutter/material.dart';
import 'package:flutter_admobs_handler/flutter_admobs_handler.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
AppAdsUtil.instance
..publisherId = '7730187684799569'
..bannerAndroidAdUnitId = 'ca-app-pub-7730187684799569/3242657265'
..interstitialAndroidAdUnitId = 'ca-app-pub-7730187684799569/1683635764'
..rewardedAndroidAdUnitId = 'ca-app-pub-7730187684799569/4364167242'
..useTestAds = false
..testDeviceIds = ['YOUR_TEST_DEVICE_HASH']
..onLog = debugPrint;
await AppAdsUtil.instance.initializeAdsSdk();
runApp(const MyApp());
}
Or configure in one call via AppAdsUtil.configure.
Banner #
const AdMobBannerWidget(useAdaptiveWidth: true)
Omit adUnitIds to use AppAdsUtil.bannerAdUnitIds.
Interstitial #
final interstitial = InterstitialAdUtil(
adUnitIds: AppAdsUtil.instance.interstitialAdUnitIds,
);
await interstitial.load();
await interstitial.show();
interstitial.dispose();
Rewarded #
final rewarded = RewardedAdUtil(
adUnitIds: AppAdsUtil.instance.rewardedAdUnitIds,
);
await rewarded.load();
final result = await rewarded.show(onUserEarnedReward: (reward) {
// grant the reward
});
if (result.shown && result.rewardEarned) {
// user completed the ad
}
rewarded.dispose();
Test ads #
AppAdsUtil.useTestAds defaults to true, serving Google's official test
inventory on every placement.
Register test devices via AppAdsUtil.testDeviceIds to request production unit
IDs while still receiving test creatives during development. Each device prints
its hash in logcat as
Use RequestConfiguration.Builder().setTestDeviceIds(...).
Example #
See the example/ directory for a runnable Android/iOS sample that demonstrates banner, interstitial, and rewarded ads.
cd example
flutter run
Contributing #
Issues and pull requests are welcome on GitHub.
License #
MIT — see LICENSE.