AdsManager class

Single entry point for every ad type this package supports.

Call init once, at app startup, then use interstitial, rewarded, rewardedInterstitial, appOpen and countedInterstitial to show ads, and AdBannerWidget anywhere in your widget tree for banners.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await AdsManager.instance.init(
    adUnitIds: const AdUnitIdSet(
      android: AdUnitIds(
        banner: 'ca-app-pub-.../...',
        interstitial: 'ca-app-pub-.../...',
        rewarded: 'ca-app-pub-.../...',
        rewardedInterstitial: 'ca-app-pub-.../...',
        appOpen: 'ca-app-pub-.../...',
      ),
      ios: AdUnitIds(
        banner: 'ca-app-pub-.../...',
        interstitial: 'ca-app-pub-.../...',
        rewarded: 'ca-app-pub-.../...',
        rewardedInterstitial: 'ca-app-pub-.../...',
        appOpen: 'ca-app-pub-.../...',
      ),
    ),
  );
  runApp(const MyApp());
}

Properties

appOpen AppOpenAdController
Full-screen ad shown when the user brings the app to the foreground.
final
GDPR/UK/US consent (UMP) handling. init uses this automatically unless you pass requestConsent: false.
final
countedInterstitial CountedInterstitialController
Shows an interstitial only every Nth time a named trigger fires.
latefinal
fullScreenAdVisibility ValueListenable<bool>
True while any full-screen ad (interstitial, rewarded, rewarded interstitial or app open) is on screen.
no setter
hashCode int
The hash code for this object.
no setterinherited
interstitial InterstitialAdController
Full-screen ad shown between content transitions.
final
isInitialized bool
Whether init has completed.
no setter
keywords List<String>
Keywords describing your app or its current content (e.g. ['sports', 'basketball']), sent with every ad request this package makes — banners, interstitials, rewarded, rewarded interstitial and app open — to help AdMob pick more relevant (and often better-paying) ads.
getter/setter pair
rewarded RewardedAdController
Full-screen ad that rewards the user for watching to completion.
final
rewardedInterstitial RewardedInterstitialAdController
Full-screen ad shown at natural transition points that also rewards the user for watching (opt-in, unlike a plain rewarded ad).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
unitIds AdUnitIds
The ad unit IDs currently in effect: Google's TestAdUnitIds if useTestAds was true at init time, otherwise the AdUnitIdSet you configured.
no setter

Methods

dispose() → void
Releases every cached ad and stops app-open lifecycle observation. Most apps never need to call this since AdsManager lives for the whole app lifetime.
init({required AdUnitIdSet adUnitIds, bool useTestAds = kDebugMode, bool requestConsent = true, List<String> testDeviceIds = const [], List<String> keywords = const [], bool preloadInterstitial = true, bool preloadRewarded = false, bool preloadRewardedInterstitial = false, bool preloadAppOpen = false, bool showAppOpenOnResume = false}) Future<void>
Initializes the Google Mobile Ads SDK, requests GDPR/UMP consent if needed, and optionally preloads ad types up front.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openAdInspector() Future<String?>
Opens Google's Ad Inspector for on-device debugging of ad requests and mediation. Intended for developer/QA use only — gate this behind a debug-only or hidden entry point in your app, never expose it to ordinary users.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance AdsManager
The shared AdsManager instance.
final