AdBreakPlacement constructor
AdBreakPlacement({
- required BreakType type,
- String? name,
- H5BeforeAdCallback? beforeAd,
- H5AfterAdCallback? afterAd,
- H5BeforeRewardCallback? beforeReward,
- H5AdDismissedCallback? adDismissed,
- H5AdViewedCallback? adViewed,
- H5AdBreakDoneCallback? adBreakDone,
Creates an ad placement configuration that can be passed to adBreak
.
The following parameters are available:
type
: The type of the placement. See BreakType.name
: A name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. Recommended.beforeAd
: Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes..afterAd
: Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actionsbeforeReward
: Called if a rewarded ad is available. The function should take a single argumentshowAdFn
which must be called to display the rewarded ad.adDismissed
: Called if the player dismisses the ad before it completes. In this case the reward should not be granted.adViewed
: Called when the player completes the ad and should be granted the reward.adBreakDone
: Always called as the last step in anadBreak
, even if there was no ad shown. Takes as argument aplacementInfo
object. See AdBreakDonePlacementInfo, and: https://developers.google.com/ad-placement/apis/adbreak#adbreakdone_and_placementinfo
This factory can create any type of placement configuration. Read the Placement Types documentation for more information.
Implementation
factory AdBreakPlacement({
required BreakType type,
String? name,
H5BeforeAdCallback? beforeAd,
H5AfterAdCallback? afterAd,
H5BeforeRewardCallback? beforeReward,
H5AdDismissedCallback? adDismissed,
H5AdViewedCallback? adViewed,
H5AdBreakDoneCallback? adBreakDone,
}) {
return AdBreakPlacement._toJS(
type: type.name.toJS,
name: '$_namePrefix${name ?? ''}'.toJS,
beforeAd: beforeAd?.toJS,
afterAd: afterAd?.toJS,
beforeReward: beforeReward != null
? (JSFunction showAdFn) {
beforeReward(() {
// Delay the call to `showAdFn` so tap users don't trigger a click on the
// ad on pointerup. This should leaves enough time for Flutter to settle
// its tap events, before triggering the H5 ad.
Timer(const Duration(milliseconds: 100), () {
showAdFn.callAsFunction();
});
});
}.toJS
: null,
adDismissed: adDismissed?.toJS,
adViewed: adViewed?.toJS,
adBreakDone: adBreakDone?.toJS,
);
}