AdManager class

Core entry point for ad management.

AdManager provides both a Widget API and an Imperative API for managing AdMob ads. It is state-management-agnostic and does not use singletons, making it fully testable via dependency injection.

Quick Start

final adManager = AdManager(
  config: AdConfig(
    bannerId: AdUnitId(
      android: 'ca-app-pub-xxxxx/banner-android',
      ios: 'ca-app-pub-xxxxx/banner-ios',
    ),
  ),
);

await adManager.initialize();

Lifecycle

Always call dispose when the manager is no longer needed to release all ad resources and cancel subscriptions.

See also:

Implementers

Constructors

AdManager({required AdConfig config})
Creates an AdManager with the given config.

Properties

config AdConfig
The configuration used by this manager.
no setter
Access to the UMP consent manager.
no setter
hashCode int
The hash code for this object.
no setterinherited
interstitialState AdState
The current state of the interstitial ad.
no setter
isInitialized bool
Whether initialize has been called successfully.
no setter
onAdEvent Stream<AdEvent>
A broadcast stream of all ad events.
no setter
rewardedState AdState
The current state of the rewarded ad.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(void listener(AdEvent event)) → void
Registers an event listener callback.
disableAppOpenAd() → void
Disables app-open ads and unregisters the lifecycle observer.
dispose() → void
Releases all ad resources and cancels subscriptions.
emitEvent(AdEvent event) → void
Emits an event to both the stream and registered listeners.
enableAppOpenAd() → void
Enables app-open ads.
initialize() Future<void>
Initializes AdMob SDK and runs the UMP consent flow.
loadInterstitial() Future<void>
Preloads an interstitial ad.
loadRewarded() Future<void>
Preloads a rewarded ad.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeListener(void listener(AdEvent event)) → void
Removes a previously registered event listener.
showInterstitial() Future<bool>
Shows a preloaded interstitial ad.
showRewarded() Future<AdReward?>
Shows a preloaded rewarded ad and returns the reward.
toString() String
A string representation of this object.
inherited

Operators

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

Constants

maxConcurrentAds → const int
Maximum concurrent ad instances.