MobileAds class

The basic class to use Ads. It's responsible to initialize the SDK and make sure you are:

  • using the right system version;
  • using test devices and test ids;
  • targeting the right groups of people.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

appOpenAdTestUnitId String
no setter
appOpenAdUnitId String?
getter/setter pair
bannerAdTestUnitId String
no setter
bannerAdUnitId String?
getter/setter pair
interstitialAdTestUnitId String
no setter
interstitialAdUnitId String?
getter/setter pair
interstitialAdVideoTestUnitId String
no setter
isInitialized bool
Check if the SDK is initialized. To initialize it, use MobileAds.initialize()
no setter
nativeAdTestUnitId String
no setter
nativeAdUnitId String?
getter/setter pair
nativeAdVideoTestUnitId String
no setter
osVersion int
Get the current version of the os. It's used to define what platform view is going to be used.
no setter
pluginChannel MethodChannel
no setter
rewardedAdTestUnitId String
no setter
rewardedAdUnitId String?
getter/setter pair
rewardedInterstitialAdTestUnitId String
no setter
rewardedInterstitialAdUnitId String?
getter/setter pair
useHybridComposition bool
Check if hybrid composition is enabled on android. It's enabled by default if the android version is 19 and on iOS. Do NOT set it before MobileAds.initialize(). Note that on Android versions prior to Android 10 Hybrid Composition has some performance drawbacks.
getter/setter pair

Static Methods

initialize({String? nativeAdUnitId, String? bannerAdUnitId, String? interstitialAdUnitId, String? rewardedAdUnitId, String? appOpenAdUnitId, String? rewardedInterstitialAdUnitId, bool? useHybridComposition}) Future<void>
Before creating any native ads, you must initalize the admob. This can be done only once, ideally at app launch. If you try to initialize it more than once, an AssertionError is thrown
isTestDevice() Future<bool>
Returns true if this device will receive test ads. Always return false on iOS
requestTrackingAuthorization() Future<TrackingAuthorizationStatus>
Display App Tracking Transparency authorization request on iOS. This has effect only on iOS
setAppMuted([bool muted = true]) Future<void>
To inform the SDK that the app volume has been muted, use the setAppMuted() method:
setAppVolume(double volume) Future<void>
If your app has its own volume controls (such as custom music or sound effect volumes), disclosing app volume to the Google Mobile Ads SDK allows video ads to respect app volume settings. This ensures users receive video ads with the expected audio volume.
setChildDirected(bool directed) Future<void>
For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called "tag for child-directed treatment". By setting this tag, you certify that this notification is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this setting may result in termination of your Google account.
setMaxAdContentRating(int maxRating) Future<void>
Apps can set a maximum ad content rating for their ad requests using the setMaxAdContentRating method. AdMob ads returned when this is configured have a content rating at or below that level. The possible values for this network extra are based on digital content label classifications, and must be one of the following values: 0, 1, 2, 3
setTagForUnderAgeOfConsent(bool underAge) Future<void>
You can mark your ad requests to receive treatment for users in the European Economic Area (EEA) under the age of consent. This feature is designed to help facilitate compliance with the General Data Protection Regulation (GDPR). Note that you may have other legal obligations under GDPR. Please review the European Union’s guidance and consult with your own legal counsel. Please remember that Google's tools are designed to facilitate compliance and do not relieve any particular publisher of its obligations under the law. Learn more about how the GDPR affects publishers.
setTestDeviceIds(List<String> ids) Future<void>
Sets a list of test device IDs corresponding to test devices which will always request test ads. The test device ID for the current device is logged in logcat when the first ad request is made. Be sure to remove the code that sets these test device IDs before you release your app.