AdropBannerController.withId constructor

AdropBannerController.withId(
  1. int id, {
  2. required AdropBanner banner,
  3. void onAdReceived(
    1. AdropBanner banner
    )?,
  4. void onAdClicked(
    1. AdropBanner banner
    )?,
  5. void onAdFailedToReceive(
    1. AdropBanner banner,
    2. AdropErrorCode errorCode
    )?,
})

Banner controller class responsible for requesting banner ads.

id required view id onAdReceived optional invoked when the banner receives an ad. onAdClicked optional invoked when the AdropBanner is clicked. onAdFailedToReceive optional invoked when the banner fails to receive an ad.

Implementation

AdropBannerController.withId(
  int id, {
  required AdropBanner banner,
  this.onAdReceived,
  this.onAdClicked,
  this.onAdFailedToReceive,
})  : _banner = banner,
      _channel =
          MethodChannel(AdropChannel.bannerEventListenerChannelOf(id)) {
  _channel.setMethodCallHandler((call) async {
    switch (call.method) {
      case AdropMethod.didReceiveAd:
        onAdReceived?.call(_banner);
        break;
      case AdropMethod.didClickAd:
        onAdClicked?.call(_banner);
        break;
      case AdropMethod.didFailToReceiveAd:
        onAdFailedToReceive?.call(
            _banner, AdropErrorCode.getByCode(call.arguments));
        break;
    }
  });
}