MobileAds class Null safety

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.
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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
read-only
appOpenAdUnitId String?
read / write
bannerAdTestUnitId String
read-only
bannerAdUnitId String?
read / write
interstitialAdTestUnitId String
read-only
interstitialAdUnitId String?
read / write
interstitialAdVideoTestUnitId String
read-only
isInitialized bool
Check if the SDK is initialized. To initialize it, use MobileAds.initialize()
read-only
nativeAdTestUnitId String
read-only
nativeAdUnitId String?
read / write
nativeAdVideoTestUnitId String
read-only
osVersion int
Get the current version of the os. It's used to define what platform view is going to be used.
read-only
pluginChannel MethodChannel
read-only
rewardedAdTestUnitId String
read-only
rewardedAdUnitId String?
read / write
rewardedInterstitialAdTestUnitId String
read-only
rewardedInterstitialAdUnitId String?
read / write
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.
read / write

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.