Menu

banner ads

1 Banner Ad

Import of Banner Ad SDK:

import 'package:anythink_sdk/at_index.dart';

1.1 Load banner ads

Use The following code loads Banner ads

 _loadBannerAd() async {
    await ATBannerManager
        .loadBannerAd(placementID: 'you placementId', extraMap: {
      ATCommon.getAdSizeKey():
      // The height is calculated based on the banner aspect ratio of 320:50, 
      // if it is other aspect ratios, please calculate according to the actual.  
      ATBannerManager.createLoadbannerAdSize(width, width * (50 / 320)),
    });
  }

ATBannerManager.createLoadbannerAdSize(width,height) description:

width: The width of the Banner display area

height: The height of the Banner display area

Note: This parameter setting must be passed when loading Banner ads, otherwise the Banner will not achieve the expected display effect.

Admob adaptive banner:

// For the Admob platform, support Admob banner advertising adaptive

    //ATBannerManager.adaptiveOrientationCurrent() self-adaptation
    //ATBannerManager.adaptiveOrientationPortrait() Portrait screen
    //ATBannerManager.adaptiveOrientationLandscape() landscape

 _loadBannerAd() async {
    await ATBannerManager
        .loadBannerAd(placementID: 'you placementId', extraMap: {
      ATCommon.getAdSizeKey():
        ATBannerManager.createLoadbannerAdSize(width, width * (50 / 320)),
      ATBannerManager.getAdaptiveWidthKey(): width,
      ATBannerManager.getAdaptiveOrientationKey(): ATBannerManager.adaptiveOrientationCurrent(),
    });
  }

1.2 Determine whether there is an ad cache and obtain the ad status

Use the following Code to determine whether there is an ad cache:

_hasBannerAdReady() async {
    await ATBannerManager
        .bannerAdReady(
      placementID: 'b5bacad80a0fb1',
    )
        .then((value) {
      print('flutter: banner ready $value');
    });
  }

Get the current ad slot Information about all available ads

getBannerValidAds() async {
    await ATBannerManager
        .getBannerValidAds(
      placementID: Configuration.bannerPlacementID,
    ).then((value) {
      print('flutter: banner ad info $value');
    });
  }

1.3 Display Banner Ads

1.3.1 platformView

When the banner ad implementation method is platformView, you only need to initialize the PlatformBannerWidget component after the ad is loaded successfully. It should be noted that the following methods cannot be used for banner ads displayed using this method.

Note: It is recommended to do a good job of Banner view state control to avoid the blank situation that Banner ads appear when Flutter refreshes the interface frequently.

// hide banner
ATBannerManager.hideBannerAd(placementID:'xxx')
// remove banner
ATBannerManager.removeBannerAd(placementID:'xxx')
// reshow banner
ATBannerManager.afreshShowBannerAd(placementID:'xxx')

PlatformBannerWidget attribute description:

placementID: Advertising ID

sceneID: Scene ID (optional parameter)

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("native text"),
      ),
      body: SafeArea(
        child: Container(
          height: 200,
          color: Colors.black,
          child: PlatformBannerWidget(
            Configuration.bannerPlacementID,
          ),
        )
      ),
    );
  }
}

1.3.2 Show API

This way is to display the layout to the interface by rendering the view on the iOS side, and we provide several apis to use.

// Use coordinates for presentation
ATBannerManager.showBannerInRectangle(placementID:'xx',extraMap:{});
// Use coordinates to display and differentiate scenes
ATBannerManager.showSceneBannerInRectangle(placementID:'xx',sceneID:'xxx',extraMap:{})
// Use a fixed position to display, provides a fixed (getAdATBannerAdShowingPositionBottom) 
// and fixed at the top (getAdATBannerAdShowingPositionTop) at the bottom of the
ATBannerManager.showAdInPosition(placementID:'xx',position:ATCommon.getAdATBannerAdShowingPositionBottom());
// Use a fixed position to display with scene id, provided at the bottom of the fixed (getAdATBannerAdShowingPositionBottom) 
// and fixed at the top (getAdATBannerAdShowingPositionTop)
ATBannerManager.showSceneBannerAdInPosition(placementID:'xx',sceneID:'xx',position:ATCommon.getAdATBannerAdShowingPositionBottom());

You can manage views in the following ways

// hide banner ad 
ATBannerManager.hideBannerAd(placementID:'xxx') 
// remove banner ad
ATBannerManager.removeBannerAd(placementID:'xxx') 
// reshow banner ad 
ATBannerManager.afreshShowBannerAd(placementID:'xxx')

1.4 Implement a banner listener

ATBannerResponse attribute introduction:

InterstitialStatus: Interstitial advertising status

placementID: placementID

requestMessage: Request information (error message)

extraMap: Callback information

isDeeplinkSuccess: isDeeplinkSuccess

Examples of notifications about interstitial ad events are as follows:

_bannerListen() {

    ATListenerManager.bannerEventHandler.listen((value) {

      switch (value.bannerStatus) {
        // banner load fail
        case BannerStatus.bannerAdFailToLoadAD:
          print("flutter bannerAdFailToLoadAD ---- placementID: ${value.placementID} ---- errStr:${value.requestMessage}");
          break;
        // banner load finish
        case BannerStatus.bannerAdDidFinishLoading:
          print("flutter bannerAdDidFinishLoading ---- placementID: ${value.placementID}");
          break;
        // banner auto refresh succed(Use Atuo Refresh) 
        case BannerStatus.bannerAdAutoRefreshSucceed:
          print("flutter bannerAdAutoRefreshSucceed ---- placementID: ${value.placementID} ---- extra:${value.extraMap}");
          break;
        // banner clicked 
        case BannerStatus.bannerAdDidClick:
          print("flutter bannerAdDidClick ---- placementID: ${value.placementID} ---- extra:${value.extraMap}");
          break;
        //Deeplink  
        case BannerStatus.bannerAdDidDeepLink:
          print("flutter bannerAdDidDeepLink ---- placementID: ${value.placementID} ---- extra:${value.extraMap} ---- isDeeplinkSuccess:${value.isDeeplinkSuccess}");
          break;
        // banner show succeed
        case BannerStatus.bannerAdDidShowSucceed:
          print("flutter bannerAdDidShowSucceed ---- placementID: ${value.placementID} ---- extra:${value.extraMap}");
          break;
        // banner closed
        case BannerStatus.bannerAdTapCloseButton:
          print("flutter bannerAdTapCloseButton ---- placementID: ${value.placementID} ---- extra:${value.extraMap}");
          break;
        // banner auto refresh fail(Use Atuo Refresh)
        case BannerStatus.bannerAdAutoRefreshFail:
          print("flutter bannerAdAutoRefreshFail ---- placementID: ${value.placementID} ---- errStr:${value.requestMessage}");
          break;
        case BannerStatus.bannerAdUnknown:
          print("flutter bannerAdUnknown");
          break;
      }
    });
  }


Previous
Interstitials ads
Next
native ads
Last modified: 2025-05-30Powered by