Huawei Ads Kit Flutter Plugin


Contents

1. Introduction

This plugin enables communication between Huawei Ads SDK and Flutter platform. Huawei Ads Kit Plugin for Flutter provides the following 2 services:

  • Publisher Service: HUAWEI Ads Publisher Service utilizes Huawei's vast user base and extensive data capabilities to deliver targeted, high quality ad content to users. With this service, your app will be able to generate revenues while bringing your users content which is relevant to them.
  • Identifier Service: HUAWEI Ads Kit provides the open advertising identifier (OAID) for advertisers to deliver personalized ads and attribute conversions.
  • HMSLogger: HMSLogger used for sending usage analytics of Ads SDK's methods to improve the service quality.

2. Installation Guide

  • Complate the HUAWEI Ads Publisher Service integration process by referring to App Integration Process.

  • Create an ad unit for refering to Add app and unit.

  • On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies to download the package from pub.dev.

 dependencies:
  huawei_ads: {library version}

or

If you downloaded the package from the HUAWEI Developer website, specify the library path on your local device.

 dependencies:
  huawei_ads:
# Replace {library path} with actual library path of Huawei Ads Kit Plugin for Flutter.
path: {library path}
  • Run
 flutter pub get

or

From Android Studio/IntelliJ: Click the Packages get action ribbon which appears on the top right corner when you open the pubspec.yaml file.

From VS Code: Click Get Packages located in right side of the action ribbon at the top of pubspec.yaml.

  • Add a corresponding import statement in the Dart code and start the app.

3. API Reference

This section does not cover all of the API. To read more, please visit HUAWEI Developer website.

Ads

AdListener

A function type defined for listening to ad events.

DefinitionDescription
void AdListener(AdEvent event, {int errorCode})Ad status listener.

Parameters

NameTypeDescription
eventAdEventAd event.
errorCodeintErrorCode.

AdEvent

Enumerated object that represents the events of an ad.

Enum Values

ValuesDescription
clickedAd is tapped.
closedAd is closed.
failedAd request failed.
impressionAn impression is recorded for an ad.
leaveAd leaves an app.
loadedAd is loaded successfully.
openedAd is opened.
dislikedAd is disliked.

AdParam

Ad request parameters.

Properties

NameTypeDescription
genderintUser gender.
countryCodeintCode of the country/region to which an app belongs.
requestOptionsRequestOptionsChild-directed setting, setting directed to users under the age of consent, and ad content rating.

AdSize

Ad size.

Constructor Summary

ConstructorDescription
AdSize({int width, int height})Ad size constructor.

Constructors

AdSize({int width, int height})

NameTypeDescription
widthfinal intAd height.
heightfinal intAd width.

HwAds

Ad initialization.

Method Summary

Return TypeMethodDescription
Future<void>init()Initializes the HUAWEI Ads SDK.
Future<void>initWithAppCode(String appCode)Initializes the HUAWEI Ads SDK.
Future<String>getSdkVersionObtains the version number of the HUAWEI Ads SDK.
Future<RequestOptions>getRequestOptionsObtains the global request configuration.
Future<void>setRequestOptions(RequestOptions options)Provides the global ad request configuration.
Future<void>setConsent(String consent)Provides the consent configuration.
Future<void>enableLogger()This method enables the HMSLogger capability which is used for sending usage analytics of Ads SDK's methods to improve the service quality.
Future<void>disableLogger()This method disables the HMSLogger capability which is used for sending usage analytics of Ads SDK's methods to improve the service quality.

Methods

init()

Initializes the HUAWEI Ads SDK.

Return Type

TypeDescription
Future<void>Future result of an execution that returns no value.

Call Example

await HwAds.init();

initWithAppCode(String appCode)

Initializes the HUAWEI Ads SDK.

Parameters

NameTypeDescription
appCodeStringApp code.

Return Type

TypeDescription
Future<void>Future result of an execution that returns no value.

Call Example

await HwAds.initWithAppCode(appCode);

getSdkVersion

Obtains the version number of the HUAWEI Ads SDK.

Return Type

TypeDescription
Future<String>Obtains the version number of the HUAWEI Ads SDK.

Call Example

String sdkVersion = await HwAds.getSdkVersion;

getRequestOptions

Obtains the global request configuration.

Return Type

TypeDescription
Future<RequestOptions>Global RequestOptions.

Call Example

RequestOptions options = await HwAds.getRequestOptions;

setRequestOptions(RequestOptions options)

Provides the global ad request configuration.

Parameters

NameTypeDescription
optionsRequestOptionsRequestOptions to set globally.

Return Type

TypeDescription
Future<void>Future result of an execution that returns no value.

Call Example

await HwAds.setRequestOptions(RequestOptions());

Provides the consent configuration.

Parameters

NameTypeDescription
consentStringConsent.

Return Type

TypeDescription
Future<void>Future result of an execution that returns no value.

Call Example

await HwAds.setConsent(consent);

enableLogger()

This method enables the HMSLogger capability which is used for sending usage analytics of Ads SDK's methods to improve the service quality.

Return Type

TypeDescription
Future<void>Future result of an execution that returns no value.

Call Example

await HwAds.enableLogger();

disableLogger()

This method disables the HMSLogger capability which is used for sending usage analytics of Ads SDK's methods to improve the service quality.

Return Type

TypeDescription
Future<void>Future result of an execution that returns no value.

Call Example

await HwAds.disableLogger();

RequestOptions

Child-directed setting, setting directed to users under the age of consent, and ad content rating.

Constructor Summary

ConstructorDescription
RequestOptions({ String adContentClassification, String tagForUnderAgeOfPromise, int tagForChildProtection, int nonPersonalizedAd, String appCountry, String appLang, String consent })Constructor for global ad request options.

Constructors

RequestOptions({ String adContentClassification, String tagForUnderAgeOfPromise, int tagForChildProtection, int nonPersonalizedAd, String appCountry, String appLang, String consent })

NameTypeDescription
adContentClassificationStringAd content rating.
tagForUnderAgeOfPromiseintThe setting directed to users under the age of consent.
tagForChildProtectionintChild-directed setting.
nonPersonalizedAdintWhether to request non-personalized ads.
appCountryStringThe country code corresponding to the language in which an ad needs to be returned for an app.
appLangStringThe language in which an ad needs to be returned for an app.
consentStringProvides the consent configuration.

VideoConfiguration

Video configuration used to control video playback.

Constructor Summary

ConstructorDescription
VideoConfiguration({ int audioFocusType, bool customizeOperationRequested, bool startMuted })Video configuration constructor.

Constructors

VideoConfiguration({ int audioFocusType, bool customizeOperationRequested, bool startMuted })

NameTypeDescription
audioFocusTypeintVideo playback scenario where the audio focus needs to be obtained.
customizeOperationRequestedboolWhether a custom video control is used for a video ad.
startMutedboolWhether a video is initially muted.

Contains classes for banner ads.

BannerAdSize

Banner ad size.

Constructor Summary

ConstructorDescription
const BannerAdSize({ int width, int height }) : super(width: width, height: height)Banner ad size constructor. Extends ad size.

Constants

ConstantsTypeDescription
s360x57BannerAdSizeBanner ad size: 360 x 57 dp
s360x144BannerAdSizeBanner ad size: 360 x 144 dp
s320x50BannerAdSizeBanner ad size: 320 x 50 dp
s468x60BannerAdSizeBanner ad size: 468 x 60 dp
s320x100BannerAdSizeBanner ad size: 320 x 100 dp
s728x90BannerAdSizeBanner ad size: 728 x 90 dp
s300x250BannerAdSizeBanner ad size: 300 x 250 dp
s160x600BannerAdSizeBanner ad size: 160 x 600 dp
sInvalidBannerAdSizeInvalid size. No ad can be requested using this size.
sDynamicBannerAdSizeDynamic banner ad size. The width of the parent layout and the height of the ad content are used.
sSmartBannerAdSizeDynamic banner ad size. The screen width and an adaptive height are used.

Method Summary

Return TypeMethodDescription
Future<int>getWidthPxObtains the ad width, in pixels. If it fails to be obtained, –1 is returned.
Future<int>getHeightPxObtains the ad height, in pixels. If it fails to be obtained, –1 is returned.
boolisAutoHeightSizeChecks whether an adaptive height is used.
boolisDynamicSizeChecks whether a dynamic size is used.
boolisFullWidthSizeChecks whether a full-screen width is used.
Future <BannerAdSize>getCurrentDirectionBannerSize(int width)Creates a banner ad size based on the current device orientation and a custom width.
Future <BannerAdSize>getLandscapeBannerSize(int width)Creates a banner ad size based on a custom width in landscape orientation.
Future <BannerAdSize>getPortraitBannerSize(int width)Creates a banner ad size based on a custom width in portrait orientation.

Methods

getWidthPx

Obtains the ad width, in pixels. If it fails to be obtained, –1 is returned.

Return Type

TypeDescription
Future<int>width in px.

Call Example

double width = await BannerAdSize.s320x50.getWidthPx;

getHeightPx

Obtains the ad height, in pixels. If it fails to be obtained, –1 is returned.

Return Type

TypeDescription
Future<int>height in px.

Call Example

double height = await BannerAdSize.s320x50.getHeightPx;

isAutoHeightSize

Checks whether an adaptive height is used.

Return Type

TypeDescription
boolAdaptive height is used.

Call Example

bool isAutoHeight = BannerAdSize.s320x50.isAutoHeightSize;

isDynamicSize

Checks whether a dynamic size is used.

Return Type

TypeDescription
boolDynamic size is used

Call Example

bool isAutoHeight = BannerAdSize.s320x50.isDynamicSize;

isFullWidthSize

Checks whether a full-screen width is used.

Return Type

TypeDescription
boolWhether a full-screen width is used.

Call Example

bool isFullWidth = BannerAdSize.s320x50.isFullWidthSize;

getCurrentDirectionBannerSize(int width)

Creates a banner ad size based on the current device orientation and a custom width.

Return Type

TypeDescription
Future <BannerAdSize>BannerAdSize.

Call Example

BannerAdSize adSize = await BannerAdSize.getCurrentDirectionBannerSize(int width);

getLandscapeBannerSize(int width)

Creates a banner ad size based on a custom width in landscape orientation.

Return Type

TypeDescription
Future <BannerAdSize>BannerAdSize.

Call Example

BannerAdSize adSize = await BannerAdSize.getLandscapeBannerSize(int width);

getPortraitBannerSize(int width)

Creates a banner ad size based on a custom width in portrait orientation.

Return Type

TypeDescription
Future <BannerAdSize>BannerAdSize.

Call Example

BannerAdSize adSize = await BannerAdSize.getPortraitBannerSize(int width);

BannerAd

Banner ad.

Constructor Summary

ConstructorDescription
BannerAd({ String adSlotId, BannerAdSize size, int bannerRefreshTime, AdListener listener, AdParam adParam })Banner ad constructor.

Constructors

BannerAd({ String adSlotId, BannerAdSize size, int bannerRefreshTime, AdListener listener, AdParam adParam })

NameTypeDescription
adSlotIdStringAd slot ID.
sizeBannerAdSizeSize of a banner ad.
bannerRefreshTimeintRotation interval for banner ads.
adParamAdParamAd request.
listenerAdListenerAd listener for an ad.

Method Summary

Return TypeMethodDescription
voidsetAdListener(AdListener listener)Sets an ad listener for an ad.
AdListenergetAdListenerObtains an ad listener.
Future<bool>loadAd()Loads an ad.
Future<bool>show({ Gravity gravity, double offset })Displays an ad.
Future<bool>isLoading()Checks whether ads are being loaded.
Future<bool>pause()Pauses any additional processing related to an ad.
Future<bool>resume()Resumes an ad after the pause() method is called last time.
Future<bool>destroy()Destroys an ad.

Methods

setAdListener(AdListener listener)

Sets an ad listener for an ad.

Parameters

NameTypeDescription
listenerAdListenerListener for an ad.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
banner.setAdListener = (AdEvent event, {int errorCode}) {
    // your code here
};

getAdListener

Gets an ad listener for an ad.

Return Type

TypeDescription
AdListenerListener for an ad.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
AdListener listener = banner.getAdListener;

loadAd()

Loads an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
await banner.loadAd();

show({ Gravity gravity, double offset })

Displays an ad.

Parameters

NameTypeDescription
gravityGravityEnum that specifies where the banner ad should be displayed on the screen. Gravity options: bottom, center, and top
offsetdoubleVertical offset from the specified position. NOTE: A positive offset value from the top will slide the ad downwards. Otherwise, the ad slides upwards.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
await banner.show(
    gravity: Gravity.bottom,
    offset: 0.0,
);

isLoading()

Checks whether ads are loading.

Return Type

TypeDescription
Future<bool>Whether an ad is loading.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
bool loading = await banner.isLoading();

pause()

Pauses any additional processing related to an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
await banner.pause();

resume()

Resumes an ad after the pause() method is called last time.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
await banner.resume();

destroy()

Destroys an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

BannerAd banner = BannerAd(adSlotId: _testAdSlotId, size: BannerAdSize.sSmart, adParam: adParam);
await banner.destroy();

Gravity

Enum Values

ValuesDescription
bottomAd is displayed at the bottom of the screen.
centerAd is displayed at the center of the screen.
topAd is displayed on the top of the screen.

BannerView

Banner Ad Widget which utilizes Android Platform Views.

Constructor Summary

ConstructorDescription
BannerView({String adSlotId, BannerAdSize size, Color backgroundColor, bool loadOnStart, Duration refreshDuration, BannerViewController controller, AdParam adParam})BannerView constructor.

Constructors

BannerView({String adSlotId, BannerAdSize size, Color backgroundColor, bool loadOnStart, Duration refreshDuration, BannerViewController controller, AdParam adParam})

NameTypeDescription
adSlotIdStringAd slot ID.
sizeBannerAdSizeSize of the BannerView. (Default value is BannerAdSize.s320x50.)
backgroundColorColorBackground color of the BannerView.
refreshDurationDurationRefresh duration of the banner ad.
loadOnStartboolShould banner bd loaded after Platform View creation. (Default value is true. If there is no BannerViewController specified for this view, this value ignored and overriden to true.)
controllerBannerViewControllerController for listening ad events and operate functions over BannerView.
adParamAdParamAd params.

BannerViewController

Controller for Banner Ad Widget.

Constructor Summary

ConstructorDescription
BannerViewController({AdListener listener, Function onBannerViewCreated})BannerViewController constructor.

Constructors

BannerViewController({AdListener listener, Function onBannerViewCreated})

NameTypeDescription
AdListenerlistenerListener for ad evenets.
FunctiononBannerViewCreatedCalled when BannerView is created.

Method Summary

Return TypeMethodDescription
Future<bool>pause()Pauses banner ad.
Future<bool>resume()Resumes banner ad.
Future<bool>loadAd()loads ad when loadOnStart specified to false on BannerView.
Future<bool>isLoading()loading status of banner ad.

Methods

loadAd()

Loads an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

bannerViewController.loadAd();

isLoading()

Checks whether ads are being loaded.

Return Type

TypeDescription
Future<bool>Whether an ad is loading.

Call Example

bool loading = await bannerViewController.isLoading();

pause()

Pauses any additional processing related to an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await bannerViewController.pause();

resume()

Resumes an ad after the pause() method is called last time.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await bannerViewController.resume();

Interstitial Ad

Contains classes for interstitial ads.

InterstitialAd

Interstitial ad.

Constructor Summary

ConstructorDescription
InterstitialAd({ String adSlotId, bool openInHmsCore, AdParam adParam, AdListener listener, RewardAdListener rewardAdListener })Interstitial ad constructor.

Constructors

InterstitialAd({ String adSlotId, bool openInHmsCore, AdParam adParam, AdListener listener, RewardAdListener rewardAdListener })

NameTypeDescription
adSlotIdStringAd slot ID.
openInHmsCoreboolDecides to reward ad will be opened on independed HmsCore activity outside of client app.
adParamAdParamAd request.
listenerAdListenerAd listener.
rewardAdListenerRewardAdListenerRewared ad listener.

Method Summary

Return TypeMethodDescription
voidsetAdListener(AdListener listener)Sets an ad listener for an ad.
AdListenergetAdListenerObtains an ad listener.
RewardAdListenersetRewardAdListener(RewardAdListener listener)Sets a rewarded ad listener for an interstitial ad.
AdListenergetRewardAdListenerObtains a rewarded ad listener from an interstitial ad.
Future<bool>loadAd()Loads an ad.
Future<bool>isLoading()Checks whether ads are being loaded.
Future<bool>isLoaded()Checks whether ad loading is complete.
Future<bool>show()Displays an ad.
Future<bool>destroy()Destroys an ad.

Methods

setAdListener(AdListener listener)

Sets an ad listener for an ad.

Parameters

NameTypeDescription
listenerAdListenerSets an ad listener.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
interstitialAd.setAdListener = (AdEvent event, {int errorCode}) {
    // your code here
};

getAdListener

Sets an ad listener for an ad.

Return Type

TypeDescription
AdListenerListener function for ad events. If it is not set, null is returned.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
AdListener listener = interstitialAd.getAdListener;

setRewardAdListener(RewardAdListener listener)

Sets a rewarded ad listener for an interstitial ad.

Parameters

NameTypeDescription
listenerRewardAdListenerListener function for rewarded ad events.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
interstitialAd.setRewardAdListener = (RewardAdEvent event, {Reward reward, int errorCode}) {
    // your code here
};

getRewardAdListener

Obtains a rewarded ad listener from an interstitial ad.

Return Type

TypeDescription
RewardAdListenerListener function for ad events. If it is not set, null is returned.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
RewardAdListener listener = interstitialAd.getRewardAdListener;

loadAd()

Initiates a request to load an ad. The android.permission.INTERNET permission must be added. If the ad slot ID is not set, IllegalStateException is thrown on the platform side.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
await interstitialAd.loadAd();

show()

Displays an interstitial ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
await interstitialAd.loadAd();
await interstitialAd.show();

isLoading()

Checks whether ads are being loaded.

Return Type

TypeDescription
Future<bool>Whether an ad is being loaded.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
bool loading = await interstitialAd.isLoading();

isLoaded()

Checks whether ad loading is complete.

Return Type

TypeDescription
Future<bool>Whether an ad has been loaded.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
bool loaded = await interstitialAd.isLoaded();

destroy()

Destroys an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InterstitialAd interstitialAd = InterstitialAd(adSlotId: adSlotId, adParam: _adParam);
await interstitialAd.destroy();

Reward Ad

Contains classes and other utilities for rewarded ads.

Reward

Information about the reward item in a rewarded ad.

Properties

NameTypeDescription
namefinal StringName of a reward item.
amountfinal intNumber of reward items.

RewardAd

Rewarded ad.

Constructor Summary

ConstructorDescription
RewardAd({ String userId, String data, bool openInHmsCore, RewardAdListener listener })Rewarded ad constructor.

Constructors

RewardAd({ String userId, String data, bool openInHmsCore, RewardAdListener listener })

NameTypeDescription
userIdStringUser ID.
dataStringCustom data.
openInHmsCoreboolDecides to reward ad will be opened on independed HmsCore activity outside of client app.
listenerRewardAdListenerReward ad listener.

Method Summary

Return TypeMethodDescription
RewardAdListenergetRewardAdListenerObtains a rewarded ad loading listener.
voidsetRewardAdListener(RewardAdListener listener)Sets a rewarded ad listener.
Future<Reward>getReward()Obtains reward item information.
Future<bool>loadAd({ String adSlotId, AdParam adParam })Requests a rewarded ad.
Future<bool>isLoaded()Checks whether a rewarded ad is successfully loaded.
Future<bool>show()Displays a rewarded ad.
Future<bool>pause()Pauses a rewarded ad.
Future<bool>resume()Resumes a rewarded ad.
Future<bool>destroy()Destroys a rewarded ad.

Methods

getRewardAdListener

Obtains a rewarded ad listener from an interstitial ad.

Return Type

TypeDescription
RewardAdListenerRewarded ad listener.

Call Example

RewardAd rewardAd = RewardAd();

setRewardAdListener(RewardAdListener listener)

Sets a rewarded ad listener for an interstitial ad.

Parameters

NameTypeDescription
listenerRewardAdListenerRewarded ad listener.

Call Example

RewardAd rewardAd = RewardAd();
rewardAd.setRewardAdListener = (RewardAdEvent event, {Reward reward, int errorCode}) {
    // your code here
};

getReward()

Obtains reward item information.

Return Type

TypeDescription
Future<Reward>Reward item information.

Call Example

RewardAd rewardAd = RewardAd();
Reward reward = await rewardAd.getReward();

loadAd({ String adSlotId, AdParam adParam })

Loads an ad.

Parameters

NameTypeDescription
adSlotIdStringAd slot ID.
adParamAdParamAd request parameters.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

RewardAd rewardAd = RewardAd();
await rewardAd.loadAd(
    adSlotId: _testAdSlotId, 
    adParam: _adParam,
);

show()

Displays an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

RewardAd rewardAd = RewardAd();
await rewardAd.loadAd(
    adSlotId: _testAdSlotId, 
    adParam: _adParam,
);
await rewardAd.show();

isLoaded()

Checks whether ad loading is complete.

Return Type

TypeDescription
Future<bool>Whether ad has been loaded.

Call Example

RewardAd rewardAd = RewardAd();
bool loaded = await rewardAd.isLoaded();

pause()

pause()

Pauses a rewarded ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

RewardAd rewardAd = RewardAd();
await rewardAd.pause();

resume()

resume()

Resumes a rewarded ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

RewardAd rewardAd = RewardAd();
await rewardAd.resume();

destroy()

destroy()

Destroys an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

RewardAd rewardAd = RewardAd();
await rewardAd.destroy();

RewardAdListener

Listener for rewarded ad events.

ConstructorDescription
void RewardAdListener(RewardAdEvent event, {Reward reward, int errorCode})Ad status listener.

RewardAdEvent

Enumerated object that represents the events of rewarded ads.

Enum Values

ValuesDescription
loadedRewarded ad is successfully loaded.
failedToLoadRewarded ad fails to be loaded.
openedRewarded ad is opened.
leftAppUser exits an app.
closedRewarded ad is closed
rewardedReward item when rewarded ad playback is completed.
startedRewarded ad starts playing.
completedRewarded ad playback is completed.
failedToShowRewarded ad fails to be displayed.

RewardVerifyConfig

Builder for server-side verification parameters.

Constructor Summary

ConstructorDescription
RewardVerifyConfig({ String userId, String data })Constructor for a RewardVerifyConfig object.

Constructors

RewardVerifyConfig({ String userId, String data })

NameTypeDescription
userIdStringUser ID.
dataStringCustom data.

Splash Ad

Contains classes and other utilities for splash ads.

SplashAd

Splash ad.

Constructor Summary

ConstructorDescription
SplashAd({ SplashAdType adType, SplashAdDisplayListener displayListener, SplashAdLoadListener loadListener, String ownerText, String footerText, String logoResId, String logoBgResId, String mediaNameResId, String sloganResId, String wideSloganResId, int audioFocusType })Splash ad constructor.

Constructors

SplashAd({ SplashAdType adType, SplashAdDisplayListener displayListener, SplashAdLoadListener loadListener, String ownerText, String footerText, String logoResId, String logoBgResId, String mediaNameResId, String sloganResId, String wideSloganResId, int audioFocusType })

NameTypeDescription
adTypeSplashAdTypeSplash ad layout type.
ownerTextStringAd owner text.
footerTextStringAd footer text.
displayListenerSplashAdDisplayListenerListener for the splash ad display or click event.
loadListenerSplashAdLoadListenerSplash ad loading listener.
logoResIdStringApp logo resource ID.
logoBgResIdStringApp background logo resource ID.
mediaNameResIdStringApp text resource ID.
sloganResIdStringDefault app launch image in portrait mode, which is displayed before a splash ad is displayed.
wideSloganResIdStringDefault app launch image in landscape mode, which is displayed before a splash ad is displayed.
audioFocusTypeintAudio focus preemption policy for a video splash ad.

Method Summary

Return TypeMethodDescription
Future<bool>preloadAd({ String adSlotId, int orientation, AdParam adParam })Preloads a splash ad.
Future<bool>loadAd({ String adSlotId, int orientation, AdParam adParam, double topMargin})Loads and displays a splash ad.
Future<bool>isLoading()Checks whether a splash ad is being loaded.
Future<bool>isLoaded()Checks whether a splash ad has been loaded.
Future<bool>pause()Suspends a splash ad.
Future<bool>resume()Resumes a splash ad.
Future<bool>destroy()Destroys a splash ad.

Methods

preloadAd({ String adSlotId, int orientation, AdParam adParam })

Preloads a splash ad.

Parameters

NameTypeDescription
adSlotIdStringAd unit ID.
orientationintScreen orientation.
adParamAdParamAd request parameters.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

SplashAd splashAd = SplashAd();
await splashAd.preloadAd(
    adSlotId: _testAdSlotId,
    orientation: SplashAdOrientation.portrait,
    adParam: _adParam,
);

loadAd({ String adSlotId, int orientation, AdParam adParam, double topMargin})

Loads and displays a splash ad.

Parameters

NameTypeDescription
adSlotIdStringAd unit ID.
orientationintScreen orientation.
adParamAdParamAd request parameters.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

SplashAd splashAd = SplashAd();
await splashAd.loadAd(
    adSlotId: _testAdSlotId,
    orientation: SplashAdOrientation.portrait,
    adParam: _adParam,
);

isLoading()

Checks whether ads are being loaded.

Return Type

TypeDescription
Future<bool>Whether a splash ad is being loaded.

Call Example

SplashAd splashAd = SplashAd();
bool loading = await splashAd.isLoading();

isLoaded()

Checks whether ad loading is complete.

Return Type

TypeDescription
Future<bool>Whether a splash ad has been loaded.

Call Example

SplashAd splashAd = SplashAd();
bool loading = await splashAd.isLoaded();

pause()

Pauses ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

SplashAd splashAd = SplashAd();
await splashAd.pause();

resume()

Resumes ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

SplashAd splashAd = SplashAd();
await splashAd.resume();

destroy()

Destroys an ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

SplashAd splashAd = SplashAd();
await splashAd.destroy();

SplashAdLoadListener

Listener for splash ad load events.

ConstructorDescription
void SplashAdLoadListener(SplashAdLoadEvent event, {int errorCode})Splash ad loading listener.

SplashAdDisplayListener

Listener for splash ad display events.

ConstructorDescription
void SplashAdDisplayListener(SplashAdDisplayEvent event)Splash ad display listener.

SplashAdLoadEvent

Enumerated object that represents the load events of splash ads.

Enum Values

ValuesDescription
loadedSplash ad is loaded successfully.
dismissedSplash ad disappears.
failedToLoadSplash ad fails to be loaded.

SplashAdDisplayEvent

Enumerated object that represents the display or click events of splash ads.

Enum Values

ValuesDescription
showedSplash ad is displayed.
clickSplash ad is clicked.

Native Ad

Contains classes and other utilities for native ads.

NativeAd

Native ad widget which utilizes Android Platform Views.

Constructor Summary

ConstructorDescription
NativeAd(String adSlotId, NativeStyle styles, NativeAdType type, NativeAdController controller)Native ad constructor.

Constructors

NativeAd(String adSlotId, NativeStyle styles, NativeAdType type, NativeAdController controller)

NameTypeDescription
adSlotIdfinal StringAd slot ID.
stylesfinal NativeStylesStyle options for the views present in a native ad.
typefinal NativeAdTypeNative ad layout type.
controllerfinal NativeAdControllerController object that grants control over native ads.

NativeAdController

Controller class that gives you access to the methods that are associated with a native ad.

Method Summary

Return TypeMethodDescription
Future<VideoOperator>getVideoOperator()Obtains the video controller of an ad.
voidgotoWhyThisAdPage()Goes to the page explaining why an ad is displayed.
Future<bool>isLoading()Checks whether ads are being loaded.
voidsetAllowCustomClick()Enables custom tap gestures.
Future<bool>isCustomClickAllowed()Checks whether custom tap gestures are enabled.
Future<String>getAdSource()Obtains an ad source.
Future<String>getDescription()Obtains the description of an ad.
Future<String>getCallToAction()Obtains the text to be displayed on a button, for example, View Details or Install.
Future<String>getTitle()Obtains the title of an ad.
Future<bool>dislikeAd(DislikeAdReason reason)Does not display the current ad. After this method is called, the current ad is closed.
Future<bool>isCustomDislikeThisAdEnabled()Checks whether custom tap gestures are enabled.
Future<bool>triggerClick(Bundle bundle)Reports a tap.
Future<bool>recordClickEvent()Reports a custom tap gesture.
Future<bool>recordImpressionEvent(Bundle bundle)Reports an ad impression.
Future<List<DislikeAdReason>>getDislikeAdReasons()Obtains the choice of not displaying the current ad.
voiddestroy()Destroys an ad object.
Future<String>getAdSign()Obtains the sign of an ad.
Future<String>getWhyThisAd()Obtains the url of why this ad showing page.

Methods

getVideoOperator()

Obtains the video controller of an ad.

Return Type

TypeDescription
Future<VideoOperator>Video controller of an ad.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

VideoOperator videoOperator = await controller.getVideoOperator();

gotoWhyThisAdPage()

Goes to the page explaining why an ad is displayed.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

controller.gotoWhyThisAdPage();

isLoading()

Checks whether ads are being loaded.

Return Type

TypeDescription
Future<void>true if an ad is being loaded; false otherwise.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

bool loading = await controller.isLoading();

setAllowCustomClick()

Enables custom tap gestures.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

controller.setAllowCustomClick();

isCustomClickAllowed()

Checks whether custom tap gestures are enabled.

Return Type

TypeDescription
Future<bool>Whether custom click gestures are enabled.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

bool allowed = await controller.isCustomClickAllowed();

getAdSource()

Obtains an ad source.

Return Type

TypeDescription
Future<String>Ad source.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

String adSource = await controller.getAdSource();

getDescription()

Obtains the description of an ad.

Return Type

TypeDescription
Future<String>Description.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

String description = await controller.getDescription();

getCallToAction()

Obtains the text to be displayed on a button, for example, View Details or Install.

Return Type

TypeDescription
Future<String>Text to be displayed on a button.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

String callToAction = await controller.getCallToAction();

getTitle()

Obtains the title of an ad.

Return Type

TypeDescription
Future<String>Title of an ad.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

String title = await controller.getTitle();

dislikeAd(DislikeAdReason reason)

Does not display the current ad. After this method is called, the current ad is closed.

Parameters

NameTypeDescription
reasonDislikeAdReasonReason why a user chooses not to display the current ad.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

await controller.dislikeAd(DislikeAdReason());

isCustomDislikeThisAdEnabled()

Checks whether custom tap gestures are enabled.

Return Type

TypeDescription
Future<bool>Whether the custom ad closing is enabled.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

bool enabled = await controller.isCustomDislikeThisAdEnabled();

triggerClick(Bundle bundle)

Reports a tap.

Parameters

NameTypeDescription
bundleBundleBundled data associated with the click.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

await controller.triggerClick(Bundle());

recordClickEvent()

Reports a custom tap gesture.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

await controller.recordClickEvent();

recordImpressionEvent(Bundle bundle)

Reports an ad impression.

Parameters

NameTypeDescription
bundleBundleBundled data associated with the ad impression.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

await controller.recordImpressionEvent(Bundle());

getDislikeAdReasons()

Obtains the choice of not displaying the current ad.

Return Type

TypeDescription
Future<List<DislikeAdReason>>Choice of not displaying the current ad.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

List<DislikeAdReason> reasons = await controller.getDislikeAdReasons();

destroy()

Destroys an ad object.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

await controller.destroy();

getAdSign()

Obtains the sign of an ad.

Return Type

TypeDescription
Future<String>Sign of an ad.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

String adSign = await controller.getAdSign();

getWhyThisAd()

Obtains the url of why this ad showing page.

Return Type

TypeDescription
Future<String>The url of why this ad showing page.

Call Example

NativeAdController controller = NativeAdController();

// Use controller in NativeAd Widget
... NativeAd( adSlotId: _testAdSlotId, controller: controller)

String whyThisAdUrl = await controller.getWhyThisAd();

NativeAdConfiguration

Native ad configuration.

Constructor Summary

ConstructorDescription
NativeAdConfiguration({ AdSize adSize, int choicesPosition, int mediaDirection, int mediaAspect, bool requestCustomDislikeAd, bool requestMultiImages, bool returnUrlsForImages, VideoConfiguration configuration })NativeAdConfiguration constructor.

Constructors

NativeAdConfiguration({ AdSize adSize, int choicesPosition, int mediaDirection, int mediaAspect, bool requestCustomDislikeAd, bool requestMultiImages, bool returnUrlsForImages, VideoConfiguration configuration })

NameTypeDescription
adSizeAdSizeRequested ad size.
choicesPositionintPosition of an ad choice icon.
mediaDirectionintDirection of an ad image.
mediaAspectintAspect ratio of an ad image.
requestCustomDislikeAdboolWhether to customize the function of not displaying the ad.
requestMultiImagesboolWhether multiple ad images are requested.
returnUrlsForImagesboolWhether the SDK is allowed to download native ad images.
videoConfigurationVideoConfigurationInformation about a native video.

NativeStyles

Style options for the views present in a native ad.

Constructor Summary

ConstructorDescription
NativeAdConfiguration({ AdSize adSize, int choicesPosition, int mediaDirection, int mediaAspect, bool requestCustomDislikeAd, bool requestMultiImages, bool returnUrlsForImages, VideoConfiguration configuration })NativeAdConfiguration constructor.

Constructors

NativeAdConfiguration({ AdSize adSize, int choicesPosition, int mediaDirection, int mediaAspect, bool requestCustomDislikeAd, bool requestMultiImages, bool returnUrlsForImages, VideoConfiguration configuration })

NameTypeDescription
showMediaboolWhether to show the media content of the native ad.
mediaImageScaleTypeStringScale type of the native ad image.

Method Summary

Return TypeMethodDescription
voidsetFlag({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })Sets the style for the ad flag text view.
voidsetTitle({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })Sets the style for the ad title text view.
voidsetSource({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })Sets the style for the ad owner text view.
voidsetDescription({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })Sets the style for the ad description text view.
voidsetCallToAction({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })Sets the style for the ad action button.

Methods

setFlag({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })

Sets the style for the ad flag text view.

Parameters

NameTypeDescription
isVisibleboolIndicates whether the ad flag component is visible.
fontSizedoubleFont size of the ad flag text.
fontWeightFontWeightFont weight of the ad flag text.
colorColorColor of the ad flag text.
bgColorColorBackground color of the ad flag text view.

Call Example

NativeStyles style = NativeStyles()..setFlag();

setTitle({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })

Sets the style for the ad title text view.

Parameters

NameTypeDescription
isVisibleboolIndicates whether the title component is visible.
fontSizedoubleFont size of the title text.
fontWeightFontWeightFont weight of the title text.
colorColorColor of the title text.
bgColorColorBackground color of the title text view.

Call Example

NativeStyles style = NativeStyles()..setTitle();

setSource({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })

Sets the style for the ad owner text view.

Parameters

NameTypeDescription
isVisibleboolIndicates whether the owner component is visible.
fontSizedoubleFont size of the owner text.
fontWeightFontWeightFont weight of the owner text.
colorColorColor of the owner text.
bgColorColorBackground color of the owner text view.

Call Example

NativeStyles style = NativeStyles()..setSource();

setDescription({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })

Sets the style for the ad description text view.

Parameters

NameTypeDescription
isVisibleboolIndicates whether the description component is visible.
fontSizedoubleFont size of the description text.
fontWeightFontWeightFont weight of the description text.
colorColorColor of the description text.
bgColorColorBackground color of the description text view.

Call Example

NativeStyles style = NativeStyles()..setDescription();

setCallToAction({ bool isVisible, double fontSize, FontWeight fontWeight, Color color, Color bgColor })

Sets the style for the ad button.

Parameters

NameTypeDescription
isVisibleboolIndicates whether the button is visible.
fontSizedoubleFont size of the button text.
fontWeightFontWeightFont weight of the button text.
colorColorColor of the button text.
bgColorColorBackground color of the button.

Call Example

NativeStyles style = NativeStyles()..setCallToAction();

NativeFontWeight

Enumerated object that represents the available font weights for text.

Enum Values

ValuesDescription
normalNormal text.
boldBold text.
italicItalic text.
boldItalicBold and italic text.

DislikeAdListener

Listener function for ad dislike events. Ads that a user dislikes will not be displayed any more.

ConstructorDescription
void DislikeAdListener(AdEvent event)Listens for when a native ad is closed

DislikeAdReason

Contains the reason why a user dislikes an ad.

Method Summary

Return TypeMethodDescription
StringgetDescriptionObtains the reason why a user dislikes an ad.

Methods

getDescription

Obtains the reason why a user dislikes an ad.

Return Type

TypeDescription
StringThe reason why a user dislikes an ad.

Call Example

String descriptopn = reason.getDescription;

Instream Ad

Contains classes and other utilities for instream ads.

InstreamAdLoader

Constructor Summary

ConstructorDescription
InstreamAdLoader(String adId, Duration this.totalDuration, int maxCount, Function(List<InstreamAd>) onAdLoaded, Function(int errorCode) onAdFailed)InstreamAdLoader constructor.

Constructors

InstreamAdLoader(String adId, Duration this.totalDuration, int maxCount, Function(List<InstreamAd>) onAdLoaded, Function(int errorCode) onAdFailed)

NameTypeDescription
adIdStringAd id for InstreamAd.
totalDurationDurationTotal maximum duration for requested instream ads.
maxCountintMaximum ad count.
onAdLoadedFunction(List<InstreamAd>)Callback for retireving loaded ads.
onAdFailedFunction(int errorCode)Callback for possible errors while ad loading.

Method Summary

Return TypeMethodDescription
Future<bool>loadAd(AdParam adParam)Starts ad loading progress with an Adparam object.
Future<bool>isLoading()Returns the status of ad loading progress.

Methods

loadAd(AdParam adParam)

Starts ad loading progress with an Adparam object.

Parameters

NameTypeDescription
adParamAdParamAdParam.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

adLoader = InstreamAdLoader(
    adId: 'testy3cglm3pj0',
    totalDuration: Duration(minutes: 1),
    maxCount: 8,
    onAdLoaded: (List<InstreamAd>) { },
    onAdFailed: (int errorCode) { },
);
await adLoader.loadAd(AdParam());

isLoading()

Returns the status of ad loading progress.

Return Type

TypeDescription
Future<bool>Whether an ad is being loaded.

Call Example

adLoader = InstreamAdLoader(
    adId: 'testy3cglm3pj0',
    totalDuration: Duration(minutes: 1),
    maxCount: 8,
    onAdLoaded: (List<InstreamAd>) { },
    onAdFailed: (int errorCode) { },
);
bool isLoading = await adLoader.isLoading();

InstreamAdView

Widget for displaying instream ads.

Constructor Summary

ConstructorDescription
InstreamAdView(List<InstreamAd> instreamAds, InstreamAdViewController controller)InstreamAdView Widget constructor.

Constructors

InstreamAdView(List<InstreamAd> instreamAds, InstreamAdViewController controller)

NameTypeDescription
instreamAdsList<InstreamAd>Instream Ads to display.
controllerInstreamAdViewControllerController for InstreamAdView.

InstreamAdViewController

Controller object for InstreamAdView.

Constructor Summary

ConstructorDescription
InstreamAdViewController(Function onClick, Function(InstreamAd) onSegmentMediaChange, Function(int per, int playTime) onMediaProgress, Function(int playTime) onMediaStart, Function(int playTime) onMediaPause, Function(int playTime) onMediaStop, Function(int playTime) onMediaCompletion, Function(int playTime, int errorCode, int extra) onMediaError, Function onMute, Function onUnMute)InstreamAdViewController contructor.

Constructors

InstreamAdViewController(Function onClick, Function(InstreamAd) onSegmentMediaChange, Function(int per, int playTime) onMediaProgress, Function(int playTime) onMediaStart, Function(int playTime) onMediaPause, Function(int playTime) onMediaStop, Function(int playTime) onMediaCompletion, Function(int playTime, int errorCode, int extra) onMediaError, Function onMute, Function onUnMute)

NameTypeDescription
onClickFunctionCalled when InstreamAdView clicked.
onSegmentMediaChangeFunction(InstreamAd ad)Called when InstreamAdView changes InstreamAd.
onMediaProgressFunction(int per, int playTime)Called while InstreamAd playing.
onMediaStartFunction(int playTime)Called when InstreamAd starts to play.
onMediaPauseFunction(int playTime)Called when InstreamAd paused.
onMediaStopFunction(int playTime)Called when InstreamAd stopped.
onMediaCompletionFunction(int playTime)Called when InstreamAd complated.
onMediaErrorFunction(int playTime, int errorCode, int extra)Called when InstreamAd encounter an error while playing.
onMuteFunctionCalled when InstreamAd muted.
onUnMuteFunctionCalled when InstreamAd unmuted.

Method Summary

Return TypeMethodDescription
Future<bool>destroy()Destroys InstreamAdView.
Future<bool>isPlaying()Obtains whether the ad is playing.
Future<bool>mute()Mutes InstreamAd.
Future<bool>onClose()Closes InstreamAd.
Future<bool>pause()Pauses InstreamAd.
Future<bool>play()Plays InstreamAd.
Future<bool>removeInstreamMediaChangeListener()Removes MediaChangeListener. Media change related callbacks not called after this execution.
Future<bool>removeInstreamMediaStateListener()Removes MediaStateListener. Media state related callbacks not called after this execution.
Future<bool>removeMediaMuteListener()Removes MediaMuteListener. Media mute related callbacks not called after this execution.
Future<bool>stop()Stops InstreamAd.
Future<bool>unmute()Unmutes InstreamAd.

Methods

destroy()

Destroys InstreamAdView.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.destroy();

isPlaying()

Obtains whether the ad is playing.

Return Type

TypeDescription
Future<bool>Whether an ad is playing.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

bool playing = await controller.isPlaying();

mute()

Mutes InstreamAd.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.mute();

onClose()

Closes InstreamAd.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.onClose();

pause()

Pauses InstreamAd.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.pause();

play()

Plays InstreamAd.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.play();

removeInstreamMediaChangeListener()

Removes MediaChangeListener. Media change related callbacks not called after this execution.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.removeInstreamMediaChangeListener();

removeInstreamMediaStateListener()

Removes MediaStateListener. Media state related callbacks not called after this execution.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.removeInstreamMediaStateListener();

removeMediaMuteListener()

Removes MediaMuteListener. Media mute related callbacks not called after this execution.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.removeMediaMuteListener();

stop()

Stops InstreamAd.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.stop();

unmute()

Mutes InstreamAd.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

InstreamAdViewController controller = InstreamAdViewController();

// Use controller in InstreamAdView Widget
... InstreamAdView(instreamAds: instreamAds, controller: adViewController)

await controller.unmute();

InstreamAd

InstreamAd objects will be created for each loaded Instream Ad.

Constructor Summary

ConstructorDescription
InstreamAd(int id)InstreamAd constuctor. Created by plugin.

Constructors

InstreamAd(int id)

NameTypeDescription
idStringIdentifier for platform channel. Used by plugin.

Method Summary

Return TypeMethodDescription
Future<String>getAdSource()Obtains ad source text.
Future<String>getCallToAction()Obtains call to action text.
Future<int>getDuration()Obtains ad duration in milliseconds.
Future<String>getWhyThisAd()Obtains the url of why this ad showing page.
Future<String>getAdSign()Obtains the ad sign.
Future<bool>isClicked()Obtains whether the ad is clicked.
Future<bool>isExpired()Obtains whether the ad is expired.
Future<bool>isImageAd()Obtains whether the ad is an image ad.
Future<bool>isShown()Obtains whether the ad is shown.
Future<bool>isVideoAd()Obtains whether the ad is a video ad.
Future<bool>gotoWhyThisAdPage()Launches the why this ad page.

Methods

getAdSource()

Obtains ad source text.

Return Type

TypeDescription
Future<String>Ad source text.

Call Example

String adSource = await instreamAd.getAdSource();

getCallToAction()

Obtains call to action text.

Return Type

TypeDescription
Future<String>Call to action text.

Call Example

String callToAction = await instreamAd.getCallToAction();

getDuration()

Obtains ad duration in milliseconds.

Return Type

TypeDescription
Future<int>Ad duration in milliseconds.

Call Example

int durationInMilliseconds = await instreamAd.getDuration();

getWhyThisAd()

Obtains the url of why this ad showing page.

Return Type

TypeDescription
Future<String>The url of why this ad showing page.

Call Example

String whyThisAd = await instreamAd.getWhyThisAd();

getAdSign()

Obtains the ad sign.

Return Type

TypeDescription
Future<String>Ad sign.

Call Example

String adSign = await instreamAd.getAdSign();

isClicked()

Obtains whether the ad is clicked.

Return Type

TypeDescription
Future<bool>Whether the ad is clicked.

Call Example

bool clicked = await instreamAd.isClicked();

isExpired()

Obtains whether the ad is expired.

Return Type

TypeDescription
Future<bool>Whether the ad is expired.

Call Example

bool expired = await instreamAd.isExpired();

isImageAd()

Obtains whether the ad is an image ad.

Return Type

TypeDescription
Future<bool>Whether the ad is an image ad.

Call Example

bool isImage = await instreamAd.isImageAd();

isShown()

Obtains whether the ad is shown.

Return Type

TypeDescription
Future<bool>Whether the ad is shown.

Call Example

bool shown = await instreamAd.isShown();

isVideoAd()

Obtains whether the ad is a video ad.

Return Type

TypeDescription
Future<bool>Whether the ad is an image ad.

Call Example

bool isVideo = await instreamAd.isVideoAd();

gotoWhyThisAdPage()

Launches the why this ad page.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await instreamAd.gotoWhyThisAdPage();

Consent

Contains classes and other utilities for processing user consent.

Provides functions to process user consent.

Method Summary

Return TypeMethodDescription
ConsentinstanceRetrieves the test device id.
Future<String>getTestDeviceId()Retrieves the test device id.
Future<bool>addTestDeviceId(String deviceId)Adds a new test device id.
Future<bool>setDebugNeedConsent(DebugNeedConsent needConsent)Set whether user consent is needed.
Future<bool>setUnderAgeOfPromise(bool ageOfPromise)Whether to process ad requests as directed to users under the age of consent.
Future<bool>setConsentStatus(ConsentStatus status)Whether to display personalized ads.
voidrequestConsentUpdate(ConsentUpdateListener listener)Request consent information.
Future<bool>updateSharedPreferences(String key, int value)Update the shared preferences related to user consent
Future<int>getSharedPreferences(String key)Retrieve a shared preference related to user consent.

Methods

instance

Returns a singleton Consent instance.

Return Type

TypeDescription
ConsentConsent instance.

Call Example

Consent instance = Consent.instance;

getTestDeviceId()

Retrieves the test device id.

Return Type

TypeDescription
Future<String>Test device ID.

Call Example

String deviceId = await Consent.instance.getTestDeviceId();

addTestDeviceId(String deviceId)

Adds a new test device id.

Parameters

NameTypeDescription
deviceIdStringTest device ID.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await Consent.instance.addTestDeviceId(deviceId);

setDebugNeedConsent(DebugNeedConsent needConsent)

Set whether user consent is needed.

Parameters

NameTypeDescription
needConsentDebugNeedConsentWhether user consent is needed.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await Consent.instance.setDebugNeedConsent(DebugNeedConsent());

setUnderAgeOfPromise(bool ageOfPromise)

Whether to process ad requests as directed to users under the age of consent.

Parameters

NameTypeDescription
ageOfPromiseboolIndicates whether to process ad requests as directed to users under the age of consent.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await Consent.instance.setUnderAgeOfPromise(promise);

setConsentStatus(ConsentStatus status)

Whether to display personalized ads.

Parameters

NameTypeDescription
statusConsentStatusStatus that indicates whether the user has given consent.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await Consent.instance.setConsentStatus(ConsentStatus.PERSONALIZED);

requestConsentUpdate(ConsentUpdateListener listener)

Request consent information.

Parameters

NameTypeDescription
listenerConsentUpdateListenerListener function for consent update events.

Call Example

await Consent.instance.requestConsentUpdate((
  ConsentUpdateEvent event, {
  ConsentStatus consentStatus,
  bool isNeedConsent,
  List<AdProvider> adProviders,
  String description,
}));

updateSharedPreferences(String key, int value)

Update the shared preferences related to user consent

Parameters

NameTypeDescription
keyStringOne of the predefined keys used to update the app's shared preferences for the purpose of testing the consent service.
valueintOne of the predefined values used to update the app's shared preferences for the purpose of testing the consent service.

Return Type

TypeDescription
Future<bool>Indicates that the method has finished execution.

Call Example

await Consent.instance.updateSharedPreferences(key, value);

getSharedPreferences(String key)

Retrieve a shared preference related to user consent.

Parameters

NameTypeDescription
keyStringOne of the predefined keys used to obtain the app's shared preferences for the purpose of testing the consent service.

Return Type

TypeDescription
Future<int>Shared preference related to user consent.

Call Example

int value = await Consent.instance.getSharedPreferences(key);

ConsentUpdateListener

Enumerated object that represents the consent update events.

ConstructorDescription
void ConsentUpdateListener(ConsentUpdateEvent event, {ConsentStatus consentStatus, bool isNeedConsent, List adProviders, String description})Ad status listener.

ConsentUpdateEvent

Enumerated object that represents the consent update events.

Enum Values

ValuesDescription
successConsent update was successful.
failedConsent update failed.

AdProvider

Contains information about ad providers.

Constructor Summary

ConstructorDescription
AdProvider({ String id, String name, String serviceArea, String privacyPolicyUrl })Ad provider constructor.

Constructors

AdProvider({ String id, String name, String serviceArea, String privacyPolicyUrl })

NameTypeDescription
idStringAd provider id.
nameStringAd provider name.
serviceAreaStringService area information.
privacyPolicyUrlStringUrl for privacy policy.

Identifier Service

Contains classes for Identifier Service. After the hms-ads-identifier SDK is integrated, you can use related APIs to obtain the OAID and setting of Disable personalized ads.

AdvertisingIdClient

Obtains an AdvertisingIdClientInfo object.

Method Summary

Return TypeMethodDescription
Future<AdvertisingIdClientInfo>getAdvertisingIdInfo()Obtains the OAID and setting of Disable personalized ads.
Future<bool>verifyAdId(String adId, bool limitTracking)Verifies the OAID and setting of Disable personalized ads.

Methods

getAdvertisingIdInfo()

Obtains the OAID and setting of Disable personalized ads.

Return Type

TypeDescription
Future<AdvertisingIdClientInfo>If the operation is successful, Future succeeds to the AdvertisingIdClientInfo object. If the API fails to be called, IOException is thrown on the platform side.

Call Example

AdvertisingIdClientInfo client = await AdvertisingIdClient.getAdvertisingIdInfo();

verifyAdId(String adId, bool limitTracking)

Verifies the OAID and setting of Disable personalized ads.

Parameters

NameTypeDescription
adIdStringOAID.
limitTrackingboolSetting of Disable personalized ads.

Return Type

TypeDescription
Future<bool>true if the OAID and setting of Disable personalized ads are valid. false if the OAID and setting of Disable personalized ads are invalid.

Call Example

await AdvertisingIdClient.verifyAdId(adId, limitTracking);

AdvertisingIdClientInfo

Obtains the OAID and setting of Disable personalized ads.

Method Summary

Return TypeMethodDescription
StringgetIdObtains the current OAID.
boolisLimitAdTrackingEnabledObtains the current setting of Disable personalized ads.

Methods

getId

Obtains the current OAID.

Return Type

TypeDescription
StringAn OAID. Example: fcffd123-372b-d965-daff-77726234f5ec

Call Example

String id = clientiInfo.getId;

isLimitAdTrackingEnabled

Obtains the current setting of Disable personalized ads.

Return Type

TypeDescription
booltrue if personalized ads are disabled. false if personalized ads are not disabled.

Call Example

bool trackingEnabled = clientiInfo.isLimitAdTrackingEnabled;

Identifier Service - InstallReferrer

Contains classes for Identifier Service. After the ads-installreferrer SDK is integrated, you can use related APIs to obtain install referrer information.

InstallReferrerClient

Obtains install referrer information.

Constructor Summary

ConstructorDescription
InstallReferrerClient({ InstallReferrerStateListener stateListener, bool test })Install referrer client constructor.

Constructors

InstallReferrerClient({ InstallReferrerStateListener stateListener, bool test })

NameTypeDescription
stateListenerInstallReferrerStateListenerInstall referrer connection state listener.
testboolSpecify if it is test.

Method Summary

Return TypeMethodDescription
voidsetTestSets whether to run the service in test mode.
void[startConnection(bool isTest)](#startconnectionbool-istest)Starts the connection to the install referrer service.
voidendConnection()Ends the service connection and releases all occupied resources.
Future<bool>isReady()Indicates whether the service connection is ready.
Future<ReferrerDetails>getInstallReferrer()Obtains install referrer information.

Methods

setTest

Sets whether to run the service in test mode.

Call Example

InstallReferrerClient referer = new InstallReferrerClient();
referer.setTest = true;

startConnection(bool isTest)

Starts the connection to the install referrer service.

Parameters

NameTypeDescription
isTestboolIndicates whether to use the test mode. Set it to true for testing.

Call Example

InstallReferrerClient referer = new InstallReferrerClient();
await referer.startConnection();

endConnection()

Ends the service connection and releases all occupied resources.

Call Example

InstallReferrerClient referer = new InstallReferrerClient();
await referer.endConnection();

isReady()

Indicates whether the service connection is ready.

Return Type

TypeDescription
Future<bool>true if the service is connected and ready to be called. false if the service has not been connected and cannot be called.

Call Example

InstallReferrerClient referer = new InstallReferrerClient();
bool isReady = await referer.isReady();

getInstallReferrer()

Obtains install referrer information

Return Type

TypeDescription
Future<ReferrerDetails>Referrer information.

Call Example

InstallReferrerClient referer = new InstallReferrerClient();
ReferrerDetails details = await referer.getInstallReferrer;

InstallReferrerStateEvent

Enumerated object that represents the events of install referrer connections.

Enum Values

ValuesDescription
setupFinishedService connection is complete.
connectionClosedService connection is closed.
disconnectedConnection is lost and the service is disconnected.

InstallReferrerStateListener

Listener for install referrer state events.

ConstructorDescription
void InstallReferrerStateListener(InstallReferrerStateEvent event, {ReferrerResponse responseCode})Install referrer connection state listener.

ReferrerResponse

Enumerated object that represents install referrer result codes.

Enum Values

ValuesDescription
disconnectedFailed to connect to the service.
okConnected to the service successfully.
unavailableThe service does not exist.
featureNotSupportedThe service is not supported.
developerErrorA call error occurred.

ReferrerDetails

Describes install referrer information.

Method Summary

Return TypeMethodDescription
StringgetInstallReferrerObtains install referrer information.
intgetReferrerClickTimestampMillisecondObtains the ad click timestamp, in milliseconds.
intgetInstallBeginTimestampMillisecondObtains the app installation timestamp, in milliseconds.

Methods

getInstallReferrer

Obtains install referrer information.

Return Type

TypeDescription
StringAn install referrer defined by you. Example: this is test install referrer.

Call Example

String installreferer = refererDetails.getInstallReferrer;

getReferrerClickTimestampMillisecond

Checks whether ads are being loaded.

Return Type

TypeDescription
intTimestamp when the ad was clicked. The value is the number of milliseconds since 1970-01-01 00:00:00 UTC. Example: 1481009302123

Call Example

int clickTimestamp = refererDetails.getReferrerClickTimestampMillisecond;

getInstallBeginTimestampMillisecond

Obtains the app installation timestamp, in milliseconds.

Return Type

TypeDescription
intTimestamp when the app was installed. The value is the number of milliseconds since 1970-01-01 00:00:00 UTC. Example: 1481009302123

Call Example

int beginTimestamp = refererDetails.getInstallBeginTimestampMillisecond;

4. Configuration Description

No.

5. Preparing for Release

Before building a release version of your app you may need to customize the proguard-rules.pro obfuscation configuration file to prevent the HMS Core SDK from being obfuscated. Add the configurations below to exclude the HMS Core SDK from obfuscation. For more information on this topic refer to this Android developer guide.

<flutter_project>/android/app/proguard-rules.pro

-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}

## Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-dontwarn io.flutter.embedding.**
-keep class com.huawei.hms.flutter.** { *; }
-repackageclasses

<flutter_project>/android/app/build.gradle

buildTypes {
    debug {
        signingConfig signingConfigs.config
    }
    release {
        signingConfig signingConfigs.config
        // Enables code shrinking, obfuscation and optimization for release builds
        minifyEnabled true
        // Unused resources will be removed.
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
   }
}

6. Sample Project

This plugin includes a demo project in the example folder, there you can find more usage examples.

7. Questions or Issues

If you have questions about how to use HMS samples, try the following options:

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • Github is the official repository for these plugins, You can open an issue or submit your ideas.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.
  • Huawei Developer Docs is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.

If you run into a bug in our samples, please submit an issue to the GitHub repository.

8. Licensing and Terms

Huawei Ads Kit Flutter Plugin uses the Apache 2.0 license.

Libraries

ad_param
ad_provider
ad_size
advertising_id_client
bundle
channels
constants
dislike_ad_reason
hms_ads
hms_ads_lib
hw_ads
install_referrer_client
instream_ad
instream_ad_loader
instream_ad_view
instream_ad_view_elements
interstitial_ad
native_ad
native_ad_configuration
native_ad_controller
native_styles
referrer_details
request_options
reward_ad
reward_verify_config
splash_ad
video_configuration
video_operator
view_types